Re: [Django] #13776: is_valid() with null field value on ModelForms from models with non-nullable ForeignKeys causes ValueError

16 views
Skip to first unread message

Django

unread,
Aug 4, 2012, 1:00:17 PM8/4/12
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.2
Severity: Normal | Resolution:
Keywords: ModelForm | Triage Stage: Design
ForeignKey | decision needed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

#18441 was a duplicate

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 4, 2013, 6:45:50 PM4/4/13
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
--------------------------------------+------------------------------------

Reporter: peterbe | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.2
Severity: Normal | Resolution:
Keywords: ModelForm ForeignKey | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by jacob):

* stage: Design decision needed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:9>

Django

unread,
May 30, 2013, 10:25:39 AM5/30/13
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | elektrrrus
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:

ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by elektrrrus):

* owner: nobody => elektrrrus
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:10>

Django

unread,
Jul 23, 2013, 9:42:01 AM7/23/13
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | elektrrrus
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mjumbewu):

* cc: mjumbewu (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:11>

Django

unread,
Feb 26, 2014, 1:47:35 AM2/26/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042

Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* owner: elektrrrus => anubhav9042


--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:12>

Django

unread,
Feb 27, 2014, 3:43:40 PM2/27/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

Currently if blank=True and null is not True, ValueError is raised. The
check being in related.py #399 for ForeignKey.
a.) I think we can display a correct message depicting the problem that in
ForeignKey with null=True can only be left blank.
b.) We can stop the usage of blank=True with ForeignKey, because alone
without null=True defined it has no significance and give suitable error
message instead of raising an error. null=True alone works perfectly

Any opinions?

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:13>

Django

unread,
Feb 27, 2014, 3:43:55 PM2/27/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* cc: anubhav9042@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:14>

Django

unread,
Feb 27, 2014, 4:11:27 PM2/27/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

I hope to work on this ticket for GSoC 2014.

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:15>

Django

unread,
May 19, 2014, 1:20:14 PM5/19/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timo):

I think `blank=True` with `null=False` is acceptable. For example, you
might fill in the value of the `ForeignKey` in the object's `save()`
method.

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:16>

Django

unread,
May 20, 2014, 4:06:24 AM5/20/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

Replying to [comment:16 timo]:


> I think `blank=True` with `null=False` is acceptable. For example, you
might fill in the value of the `ForeignKey` in the object's `save()`
method.

What about `is_valid`?

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:17>

Django

unread,
May 20, 2014, 5:23:49 AM5/20/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: 1.2
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timo):

We should try to fix it so that an exception is not raised. As noted in
the django-users thread, the use-case worked in Django 1.0, but broke in
1.2.

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:18>

Django

unread,
May 26, 2014, 4:51:04 AM5/26/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: master

Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* has_patch: 0 => 1
* version: 1.2 => master


--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:19>

Django

unread,
May 26, 2014, 2:05:10 PM5/26/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: assigned
Severity: Normal | Version: master
Keywords: ModelForm | Resolution:
ForeignKey | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timo):

As discussed on IRC, the patch isn't what we want. There shouldn't be a
form error because the form is valid according to its specification.

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:20>

Django

unread,
Jun 4, 2014, 7:58:36 AM6/4/14
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
Type: Bug | anubhav9042
Component: Forms | Status: closed
Severity: Normal | Version: master
Keywords: ModelForm | Resolution: fixed

ForeignKey | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"45e049937d2564d11035827ca9a9221b86215e45"]:
{{{
#!CommitTicketReference repository=""
revision="45e049937d2564d11035827ca9a9221b86215e45"
Fixed #13776 -- Fixed ModelForm.is_valid() exception with non-nullable FK
and blank=True.

Thanks peterbe for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:21>

Django

unread,
Sep 21, 2015, 3:32:16 PM9/21/15
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
| anubhav9042
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: ModelForm | Triage Stage: Accepted
ForeignKey |

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"65a1055a36318ff4e21ffeb7c3dd62fa81892269" 65a1055]:
{{{
#!CommitTicketReference repository=""
revision="65a1055a36318ff4e21ffeb7c3dd62fa81892269"
Fixed #25431 -- Readded inline foreign keys to modelformset instances

Too much field exclusions in form's construct_instance() in _post_clean()
could lead to some unexpected missing ForeignKey values.
Fixes a regression from 45e049937. Refs #13776.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:22>

Django

unread,
Sep 21, 2015, 3:51:20 PM9/21/15
to django-...@googlegroups.com
#13776: is_valid() with null field value on ModelForms from models with non-
nullable ForeignKeys causes ValueError
-------------------------------------+-------------------------------------
Reporter: peterbe | Owner:
| anubhav9042
Type: Bug | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: ModelForm | Triage Stage: Accepted
ForeignKey |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"158b0a28374054b1c3f94a9602b69f93fc980448" 158b0a28]:
{{{
#!CommitTicketReference repository=""
revision="158b0a28374054b1c3f94a9602b69f93fc980448"
[1.8.x] Fixed #25431 -- Readded inline foreign keys to modelformset
instances

Too much field exclusions in form's construct_instance() in _post_clean()
could lead to some unexpected missing ForeignKey values.
Fixes a regression from 45e049937. Refs #13776.

Backport of 65a1055a3 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/13776#comment:23>

Reply all
Reply to author
Forward
0 new messages