#24539: Attempt to create object with repeated value on a custom PK raises
IntegrityError on wrong field
-------------------------------+--------------------------------------
Reporter: emyller | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by emyller):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> 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.
>
> Note: I noticed the exception is raised from an {{{UPDATE}}} query, which
> is really odd since I'm posting data from the admin add view.
New description:
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24539#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.087fc0a207ba6247c0e199dbf19468bc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.