Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#2214 closed defect (worksforme)

[patch] Form fields for related models not properly processed

Reported by: Russell Cloran <russell@…> Owned by: adrian
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:

Description

Hi,

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.

Russell

Attachments (1)

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

Download all attachments as: .zip

Change History (5)

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

comment:1 Changed 9 years ago by mtredinnick

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 9 years ago by Russell Cloran <russell@…>

Hi,

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:
        pass

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 9 years ago by Russell Cloran <russell@…>

  • Cc russell@… added

comment:4 Changed 9 years ago by mtredinnick

  • Resolution set to worksforme
  • Status changed from new to closed

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