[Django] #22656: Adding check for FK that blank=False when null=False

15 views
Skip to first unread message

Django

unread,
May 19, 2014, 10:38:21 AM5/19/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
----------------------------------------------+--------------------
Reporter: anubhav9042 | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
When ForeignKey is not given null=True with blank=True, there are problems
at the time of saving.

Adding a validation check enforcing that blank=False when null=False to
catch such errors/warnings and displaying appropriate message so that the
user is fully aware of the situation.

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

Django

unread,
May 19, 2014, 10:40:23 AM5/19/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: assigned
(models, ORM) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* owner: nobody => anubhav9042
* needs_docs: => 0
* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/2686

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:1>

Django

unread,
May 19, 2014, 12:46:00 PM5/19/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: assigned
(models, ORM) | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by aaugustin):

I assume you meant "blank=False when null=False" instead of "null=True
with blank=True"?

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:2>

Django

unread,
May 19, 2014, 1:13:29 PM5/19/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: assigned
(models, ORM) | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timo):

I'm not sure this is something we want to add as it will break backwards
compatibility. For example, "Leaving a field blank and filling it in in
the model's save() method seems to be a pretty common case" -from
[https://groups.google.com/d/msg/django-users/jqgDy4oo5ZQ/KUSz2gyJ8m0J
django-users].

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:3>

Django

unread,
May 19, 2014, 1:57:13 PM5/19/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: closed
(models, ORM) | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

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


Comment:

Agreed with Tim, that's a use case we want to support.

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:4>

Django

unread,
May 20, 2014, 3:41:58 AM5/20/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: closed
(models, ORM) | Version: master

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

Replying to [comment:4 aaugustin]:


> Agreed with Tim, that's a use case we want to support.


I have added this for `ForeignKey` only not for other fields. In others it
is fine but in FK it will create `database errors` on `save()` if any
object is not provided.

If null=False then keeping blank=True for `ForeignKey` is wrong and will
lead to errors in save() as said above. I think that was what I wanted to
say and could not explain earlier.

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:5>

Django

unread,
May 20, 2014, 3:46:08 AM5/20/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: closed
(models, ORM) | Version: master

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

Replying to [comment:2 aaugustin]:


> I assume you meant "blank=False when null=False" instead of "null=True
with blank=True"?

I meant the case where null=False and blank=True for `ForeignKey`

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:6>

Django

unread,
May 20, 2014, 5:28:34 AM5/20/14
to django-...@googlegroups.com
#22656: Adding check for FK that blank=False when null=False
-------------------------------------+-------------------------------------
Reporter: anubhav9042 | Owner:
Type: Bug | anubhav9042
Component: Database layer | Status: closed
(models, ORM) | Version: master

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
Has patch: 1 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timo):

As noted in #13776, the use case worked in Django 1.0, but broke in 1.2.
We should try to fix it rather than just disallow it.

--
Ticket URL: <https://code.djangoproject.com/ticket/22656#comment:7>

Reply all
Reply to author
Forward
0 new messages