Opened 18 years ago

Closed 18 years ago

Last modified 18 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: dev
Severity: normal Keywords:
Cc: russell@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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@…> 18 years ago.

Download all attachments as: .zip

Change History (5)

by Russell Cloran <russell@…>, 18 years ago

Attachment: related.diff added

comment:1 by Malcolm Tredinnick, 18 years ago

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

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

Cc: russell@… added

comment:4 by Malcolm Tredinnick, 18 years ago

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