Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #25349 - ModelForm bug that occurs when saving None value to a ForeignKey with null=True, blank=False and required=False. #5658

Closed
wants to merge 1 commit into from

Conversation

haxoza
Copy link
Contributor

@haxoza haxoza commented Nov 14, 2015

@@ -193,14 +193,7 @@ def __set__(self, instance, value):
- ``instance`` is the ``child`` instance
- ``value`` in the ``parent`` instance on the right of the equal sign
"""
# If null=True, we can assign null here, but otherwise the value needs
# to be an instance of the related class.
if value is None and self.field.null is False:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think removing this check is the right thing to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I described this change in a more detailed way here:

https://code.djangoproject.com/ticket/25349#comment:6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. I raised it on the mailing list and there is consensus to remove it. I think it should be done as a separate ticket for clarity (also needs to be documented). Are you able to do it? Here's the ticket: https://code.djangoproject.com/ticket/26179

a ForeignKey with null=True, blank=False and required=False.

The solution allows to assign None value to ForeignKey model fields
with null=False. Assignment doesn't complain immediately.
The validation is deferred to calling save() or full_clean() methods.
As a side effect this commit fixes the issue for simple model forms
with regular fields set in model to blank=False and in form to
required=False. Refs django#13776, django#7551, django#9649, django#6886.
@timgraham
Copy link
Member

Ready for a rebase after 04e13c8

@timgraham
Copy link
Member

updated and merged in 375e1cf, thanks!

@timgraham timgraham closed this Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants