Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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.

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by programmerq

  • Component changed from Uncategorized to Database wrapper
  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by cgrady

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

  • Resolution set to invalid
  • Status changed from new to closed

You are right, FK should be excluded from start.

comment:4 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.