Opened 10 years ago

Last modified 3 years ago

#24539 new Bug

Attempt to create object with repeated value on a custom PK raises IntegrityError on wrong field — at Version 1

Reported by: Evandro Myller Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no
Pull Requests:How to create a pull request

Description (last modified by Evandro Myller)

I have this model Product, child of an abstract model which defines a created field with auto_now_add set. All the CRUD works just fine so far.

The problem happens when I add a custom primary key to Product: If I try to create a Product object through the admin giving the reference field a repeated value, expecting to see a nice validation error message saying that another object with that reference already exists, I get an IntegrityError stating that the created field cannot be NULL (traceback attached) -- nothing even about the custom primary key.

Notes:

  • I noticed the exception is raised from an UPDATE query, which is really odd since I'm posting data from the admin add view.
  • Product(reference=x).save() raises the same exception, but Product.objects.create(reference=x raises the expected exception (IntegrityError about the PK's UNIQUE constraint), which proves that it's not a problem on the admin.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (3)

by Evandro Myller, 10 years ago

Attachment: traceback.txt added

full traceback

by Evandro Myller, 10 years ago

Attachment: models.py added

example models

comment:1 by Evandro Myller, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top