Opened 2 years ago

Closed 2 years ago

#19467 closed Bug (needsinfo)

Admin inlines doesn't properly call model.clean()

Reported by: glic3rinu Owned by: nobody
Component: Uncategorized Version: master
Severity: Normal Keywords: admin inline clean
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by kmtracey)

Seems that model forms or admin dones't clean correctly inline forms.

class Child(models.Model):
   parent = models.ForeignKey(Parent)
   something = models.CharField(blank=True, null=True, unique=True)

   def clean(self):
       if self.something == '':
           self.something = None
       super(Child, self).clean()

Postgres raises a: duplicate key value violates unique constraint "child_something_key"

I've made a little hack on django's code and call child.clean() just before child.save(), and then it works. Also I've tried a similar scenario with an admin.ModelAdmin instead of admin.TabularInline and it works to. So it must be a bug somewhere on the inlines.

Node: I'm using master, not tested with 1.4

thanks.

Change History (1)

comment:1 Changed 2 years ago by kmtracey

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

Fixed formatting, please use WikiFormatting and preview before posting.

Could you provide a complete example of parent/child models plus the admin classes you are using? It's going to require a bit of guesswork to try to replicate the error you describe with just a single model definition and no guidance on how you have set up the admin defs.

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