Opened 11 years ago

Closed 11 years ago

Last modified 11 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 by ANUBHAV JOSHI, 11 years ago

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

comment:2 by Aymeric Augustin, 11 years ago

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

comment:3 by Tim Graham, 11 years ago

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 by Aymeric Augustin, 11 years ago

Resolution: wontfix
Status: assignedclosed

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

in reply to:  4 comment:5 by ANUBHAV JOSHI, 11 years ago

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.

Version 1, edited 11 years ago by ANUBHAV JOSHI (previous) (next) (diff)

in reply to:  2 comment:6 by ANUBHAV JOSHI, 11 years ago

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 by Tim Graham, 11 years ago

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