#33591: Incorrect validation message
-------------------------------------+-------------------------------------
Reporter: Maria | Owner: nobody
Sorokina |
Type: Bug | Status: new
Component: Database | Version: 4.0
layer (models, ORM) | Keywords: ValidationError,
Severity: Normal | validation, message
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hello!
**What I did:** I've created a model and added a ''clean'' method to it to
validate two fields together. I've created a dictionary of errors, and
raised ''ValidationError'' with that dictionary as an argument. I've
checked creating new model in standard admin site.
**What I expected to see:** when I have an error I should see a message
"Test1".
**What I got:** I see error message "Enter a whole number.".
**What I noticed:** if I remove ''code="invalid"'' parameter then I get
the correct message "Test1".
**My code:**
{{{#!python
from django.db import models
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator, MaxValueValidator
class Confidant(models.Model):
CALENDARS = (
('L', 'Lunar'),
('G', 'Gregorian'),
('J', 'Julian'),
)
MONTHS = (
(1, 'January'),
(2, 'February'),
(3, 'March'),
(4, 'April'),
(5, 'May'),
(6, 'June'),
(7, 'July'),
(8, 'August'),
(9, 'September'),
(10, 'October'),
(11, 'November'),
(12, 'December'),
)
id = models.BigAutoField(primary_key=True)
height = models.PositiveSmallIntegerField(
validators=[
MinValueValidator(130),
MaxValueValidator(210),
],
)
birth_month = models.PositiveSmallIntegerField(choices=MONTHS)
birth_day = models.PositiveSmallIntegerField(
validators=[
MinValueValidator(1),
MaxValueValidator(31),
],
)
calendar = models.CharField(max_length=1, choices=CALENDARS)
def clean(self):
errors = {}
if (
self.birth_month == 2 and self.birth_day > 29
or self.birth_month in [4,6,9,11] and self.birth_day > 30
):
#errors['birth_day'] = ValidationError('Test1') #shows correct
message
errors['birth_day'] = ValidationError('Test1', code='invalid')
#shows wrong message
if errors:
raise ValidationError(errors)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33591>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107017fab5543ea-091ee105-f719-4316-9348-6f65e5b3c998-000000%40eu-central-1.amazonses.com.