#7585 closed (invalid)
changeset 7574 broke form.save(commit=False) on FK fields
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When trying to save a ModelForm instance with a not null foreign key without specifying the FK field but saving with commit=False
form.save(commit=False)
raises ValueError as per the following code introduced in the changeset [7574]:
...
if value is None and self.field.null == False:
raise ValueError('Cannot assign None: "%s.%s" does not allow null values.' %
(instance._meta.object_name, self.field.name))
...
commit=False should be regarded when checking for ValueError.
Change History (4)
comment:1 by , 17 years ago
| Component: | Uncategorized → Database wrapper |
|---|---|
| milestone: | → 1.0 |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
comment:3 by , 17 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
You are right, FK should be excluded from start.
Note:
See TracTickets
for help on using tickets.
I don't see the use case where this would present itself - if you have a
ForeignKeyyou're setting manually, wouldn't you useexcludeto hide it from the form entirely, so it is therefore not being set at all insave()?