The reason for that error is the space at the end of the primary key.
--
Ticket URL: <https://code.djangoproject.com/ticket/29647>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "admin.py" added.
Models and admin classes
* Attachment "admin_error.png" added.
Comment (by Tim Graham):
I can't reproduce this given the models and admin you provided. Which
version of Django are you using? Starting
[https://docs.djangoproject.com/en/dev/releases/1.9/#miscellaneous in
Django 1.9]:
CharField now strips input of leading and trailing whitespace by default.
This can be disabled by setting the new strip argument to False.
The behavior I see when editing an `Attribute` whose `name` contains a
trailing space is that a new instance is created because primary keys
aren't editable as described in #2259.
--
Ticket URL: <https://code.djangoproject.com/ticket/29647#comment:1>
Comment (by Alex Uralov):
Replying to [comment:1 Tim Graham]:
> I can't reproduce this given the models and admin you provided. Which
version of Django are you using? Starting
[https://docs.djangoproject.com/en/dev/releases/1.9/#miscellaneous in
Django 1.9]:
> CharField now strips input of leading and trailing whitespace by
default. This can be disabled by setting the new strip argument to False.
>
> The behavior I see when editing an `Attribute` whose `name` contains a
trailing space is that a new instance is created because primary keys
aren't editable as described in #2259.
I use Django==2.0.8. Could you reproduce this by steps:
1) Create a new Attribute item without spaces. For example 'test'
2) Change the name (primary key) of the attribute via db query. UPDATE
"public"."MODULE_attribute" SET "name" = 'test ' WHERE "name" = 'test'
3) Open Django admin panel and try to append any AttributeValue to 'test '
attribute.
4) I get the error message "Please correct the error below."
--
Ticket URL: <https://code.djangoproject.com/ticket/29647#comment:2>
* status: new => closed
* resolution: => invalid
Comment:
Yes, I can reproduce with those steps. Thanks. Inspecting the errors
manually, I see `[{'attribute': ['The inline value did not match the
parent instance.']}]`. I think the root cause is that the trailing space
is stripped in the parent instance but not for the child instance. I don't
think this is a bug in Django but it could be considered a duplicate of
#2259 in that the primary key probably shouldn't be editable in the first
place. I think you could fix that using `ModelAdmin.readonly_fields`.
--
Ticket URL: <https://code.djangoproject.com/ticket/29647#comment:3>
Comment (by Alex Uralov):
Thank you for the advice!
--
Ticket URL: <https://code.djangoproject.com/ticket/29647#comment:4>