Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29647 closed Bug (invalid)

"Please correct the error below." when saving edit model form with inline formset and space at the end of primary key value

Reported by: Alex Uralov Owned by: nobody
Component: contrib.admin Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have an Attribute instance in DB with name 'Motor type ' (space in the end). Also, I have AttributeValueInlineAdmin as inline for AttributeAdmin. When I try to change field display_name for that instance in Django admin I get an error "Please correct the error below." with no errors shown.

The reason for that error is the space at the end of the primary key.

Attachments (2)

admin.py (761 bytes ) - added by Alex Uralov 6 years ago.
Models and admin classes
admin_error.png (156.9 KB ) - added by Alex Uralov 6 years ago.

Download all attachments as: .zip

Change History (6)

by Alex Uralov, 6 years ago

Attachment: admin.py added

Models and admin classes

by Alex Uralov, 6 years ago

Attachment: admin_error.png added

comment:1 by Tim Graham, 6 years ago

I can't reproduce this given the models and admin you provided. Which version of Django are you using? Starting 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.

in reply to:  1 comment:2 by Alex Uralov, 6 years ago

Replying to Tim Graham:

I can't reproduce this given the models and admin you provided. Which version of Django are you using? Starting 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."

comment:3 by Tim Graham, 6 years ago

Resolution: invalid
Status: newclosed

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.

comment:4 by Alex Uralov, 6 years ago

Thank you for the advice!

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