[Django] #34805: 'Q' object has no attribute 'replace_expressions'

8 views
Skip to first unread message

Django

unread,
Aug 30, 2023, 7:50:33 AM8/30/23
to django-...@googlegroups.com
#34805: 'Q' object has no attribute 'replace_expressions'
-----------------------------------------+------------------------
Reporter: Petr Přikryl | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hi, I have problem with calling full_clean on Model object with following
constraint containing Q:

{{{
models.UniqueConstraint(
models.Q(color__isnull=True),
"product",
condition=models.Q(color__isnull=True),
name="unique_product_color_null",
),
}}}

Constraint is allowing only one NULL and works well. More at
[https://www.enterprisedb.com/postgres-tutorials/postgresql-unique-
constraint-null-allowing-only-one-null]

Traceback
{{{
/usr/local/lib/python3.11/site-packages/django/db/models/base.py:1497: in
full_clean
self.validate_constraints(exclude=exclude)
/usr/local/lib/python3.11/site-packages/django/db/models/base.py:1445: in
validate_constraints
constraint.validate(model_class, self, exclude=exclude, using=using)

/usr/local/lib/python3.11/site-
packages/django/db/models/constraints.py:346: AttributeError
> expressions.append(Exact(expr,
expr.replace_expressions(replacements)))
E AttributeError: 'Q' object has no attribute
'replace_expressions'
}}}

https://github.com/django/django/blob/4.2.4/django/db/models/constraints.py#L346

--
Ticket URL: <https://code.djangoproject.com/ticket/34805>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 30, 2023, 8:21:38 AM8/30/23
to django-...@googlegroups.com
#34805: 'Q' object has no attribute 'replace_expressions'
-------------------------------------+-------------------------------------

Reporter: Petr Přikryl | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid
* component: Uncategorized => Database layer (models, ORM)


Comment:

Your constraint definition is invalid, you cannot pass `Q` objects in
`expressions`, check out
[https://docs.djangoproject.com/en/4.2/ref/models/constraints/#expressions
docs]. If you're having trouble understanding how Django works, see
TicketClosingReasons/UseSupportChannels for ways to get help.

--
Ticket URL: <https://code.djangoproject.com/ticket/34805#comment:1>

Reply all
Reply to author
Forward
0 new messages