Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#2214 closed defect (worksforme)

[patch] Form fields for related models not properly processed

Reported by: Russell Cloran <russell@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: normal Keywords:
Cc: russell@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



When a field in a related object on a form is null=True, but the field type has empty_strings_allowed=False, and the form is submitted, blank fields are sent to get_db_prep_save() as blank strings, rather than as None.

The attached patch fixes the problem in my case. It should be reviewed, because I don't know what else it might affect.


Attachments (1)

related.diff (574 bytes) - added by Russell Cloran <russell@…> 12 years ago.

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by Russell Cloran <russell@…>

Attachment: related.diff added

comment:1 Changed 12 years ago by Malcolm Tredinnick

Can you post a model/form example that shows what you are talking about here. It sounds like if null=True and blank=False and you submit an empty string, we should be catching it long before the db_prep_save() phase.

comment:2 Changed 12 years ago by Russell Cloran <russell@…>


The following model demonstrates the bug, when you try to submit a new or updated Student in the admin interface.

class Student(models.Model):
    name = models.CharField(maxlength=20)
    class Admin:

class Registration(models.Model):
    student = models.ForeignKey(Student, edit_inline=True)
    blablabla = models.CharField(maxlength=10, core=True)
    date_paid = models.DateField(null=True, blank=True)

comment:3 Changed 12 years ago by Russell Cloran <russell@…>

Cc: russell@… added

comment:4 Changed 12 years ago by Malcolm Tredinnick

Resolution: worksforme
Status: newclosed

I cannot replicate this with the model you have given. I can enter a new student and if I enter a blablabla value, but no date_paid, it seems to go into the database correctly. Editing the student record works smoothly, too.

mysql> select * from t2214_registration;
| id | student_id | blablabla | date_paid |
|  1 |          1 | sdfggh    | NULL      |

I'm going to close this for now. If it still happens for you, particularly with the models you gave above, please reopen and post some more information. In particular, what data you entered in the admin and what the full traceback is.

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