#33335: Django admin error when adding new object, when using Django 4
functional
unique constraints on model
-------------------------------+--------------------------------------
Reporter: Hervé Le Roy | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by Hervé Le Roy):
Thank you Claude for pointing this out. I was testing outside of admin
using `tag = Tag(...); tag.save()`, which works.
But following your example, when I run `tag.full_clean()`, it fails with
the following error:
{{{
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py",
line 1261, in full_clean
raise ValidationError(errors)
django.core.exceptions.ValidationError: {'__all__': ['Tag with this
already exists.']}
}}}
The fact that there is a missing word between 'this' and 'already' is
weird. I have narrowed down the constraint causing the issue (when I
remove it, it works fine).
It's this one:
{{{
models.UniqueConstraint(Lower('name'),
name='%(app_label)s_%(class)s_name_case_insensitive'),
}}}
The ability to use positional argument *expressions in UniqueConstraint is
a new feature from Django 4.0
https://docs.djangoproject.com/en/4.0/ref/models/constraints/#expressions
I'm not expert enough to understand why `full_clean()`fails. We'll see
when 4.0 is released if I'm the only one facing this issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/33335#comment:3>
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/064.746dfdd22ecff1fd40ff4914189cd135%40djangoproject.com.