Code

Opened 5 years ago

Closed 5 years ago

#12078 closed (fixed)

ValidationError(s) from specific fields not rendered on admin add/change form

Reported by: Killarny Owned by: Honza_Kral
Component: contrib.admin Version: soc2009/model-validation
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Description

On the admin change form, ValidationErrors raised from some fields don't render properly. The message at the top of the form displays ("Please correct the errors below.") but the html for the specific error in the field row does not display. This is a problem with only some fields, but not others. For example, a ValidationError raised from a CharField when it's max_length is exceeded displays properly, but URLField and EmailField errors do not.

How to reproduce

This issue can be reproduced with a simple project with the following changes from the generated startproject and startapp:

settings.py:

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'db.sqlite'
INSTALLED_APPS = (
    ...
    'django.contrib.admin',
    ...
    'foo',
)

Uncomment the admin lines in urls.py.

foo/models.py:

from django.db import models

class Bar(models.Model):
    url = models.URLField()
    email = models.EmailField()
    three_letters = models.CharField(max_length=3)

foo/admin.py:

from django.contrib import admin
from foo import models

admin.site.register(models.Bar)

Sync the database and start the development environment, then visit http://127.0.0.1:8000/admin/foo/bar/add/ and enter values in each of the fields.

Enter valid data into the EmailField and CharField, and put "google.com" in the URLField. This should show an error along the lines of "Enter a valid URL.", but it does not.

Conversely, entering a valid url (such as "http://google.com") and putting more than the max 3 characters in the CharField will properly show an error like "Ensure this value has at most 3 characters (it has 5)."

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by Killarny

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I opened this ticket two months ago, and it's still labeled "new" and "unreviewed". Is anyone watching this branch, or has model validation been dropped?

comment:2 Changed 5 years ago by Honza_Kral

  • Owner changed from nobody to Honza_Kral
  • Status changed from new to assigned

model-validation has not been dropped, I will have a look at it. Sorry for the delay.

btw 'google.com' IS a valida value for URLField, see tests:

http://code.djangoproject.com/browser/django/branches/soc2009/model-validation/tests/regressiontests/forms/fields.py#L539

comment:3 Changed 5 years ago by Honza_Kral

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [12015]) [soc2009/model-validation] Fixed #12078 ValidationError(s) from specific fields not rendered on admin add/change form.

Thanks to Killarny for detailed report

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.