Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#22656 closed Bug (wontfix)

Adding check for FK that blank=False when null=False

Reported by: ANUBHAV JOSHI Owned by: ANUBHAV JOSHI
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (7)

comment:1 Changed 7 years ago by ANUBHAV JOSHI

Has patch: set
Owner: changed from nobody to ANUBHAV JOSHI
Status: newassigned

comment:2 Changed 7 years ago by Aymeric Augustin

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

comment:3 Changed 7 years ago by Tim Graham

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 django-users.

comment:4 Changed 7 years ago by Aymeric Augustin

Resolution: wontfix
Status: assignedclosed

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

comment:5 in reply to:  4 Changed 7 years ago by ANUBHAV JOSHI

Replying to 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.

I wanted to improve error reporting so I opened this. Also as said in #13776, what in case of is_valid??

Last edited 7 years ago by ANUBHAV JOSHI (previous) (diff)

comment:6 in reply to:  2 Changed 7 years ago by ANUBHAV JOSHI

Replying to 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

comment:7 Changed 7 years ago by Tim Graham

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.

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