Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7585 closed (invalid)

changeset 7574 broke form.save(commit=False) on FK fields

Reported by: omat@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 Changed 8 years ago by Jeff Anderson

Component: UncategorizedDatabase wrapper
milestone: 1.0
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Collin Grady

I don't see the use case where this would present itself - if you have a ForeignKey you're setting manually, wouldn't you use exclude to hide it from the form entirely, so it is therefore not being set at all in save() ?

comment:3 Changed 8 years ago by omat@…

Resolution: invalid
Status: newclosed

You are right, FK should be excluded from start.

comment:4 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top