Opened 16 years ago

Closed 16 years ago

Last modified 13 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: 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 Jeff Anderson, 16 years ago

Component: UncategorizedDatabase wrapper
milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:2 by Collin Grady, 16 years ago

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 by omat@…, 16 years ago

Resolution: invalid
Status: newclosed

You are right, FK should be excluded from start.

comment:4 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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