Re: [Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-05-14 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
 Reporter:  Mathieu Kniewallner  |Owner:  Mariusz
 |  Felisiak
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  fixed
 Keywords:   | Triage Stage:  Ready for
 |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

 * resolution:   => fixed
 * status:  assigned => closed

Comment:

 In [changeset:"f030236a86a64a4befd3cc8093e2bbeceef52a31" f030236a]:
 {{{#!CommitTicketReference repository=""
 revision="f030236a86a64a4befd3cc8093e2bbeceef52a31"
 Fixed #35275 -- Fixed Meta.constraints validation crash on
 UniqueConstraint with OpClass().

 This also introduces Expression.constraint_validation_compatible that
 allows specifying that expression should be ignored during a constraint
 validation.
 }}}
-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f763d3dca-6bf71493-56fa-42ea-ae2b-9f974e38631a-00%40eu-central-1.amazonses.com.


Re: [Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-05-14 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
 Reporter:  Mathieu Kniewallner  |Owner:  Mariusz
 |  Felisiak
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Ready for
 |  checkin
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Sarah Boyce):

 * stage:  Accepted => Ready for checkin

-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f75de7046-cbdc54d7-e220-4770-976f-d384ea9b5217-00%40eu-central-1.amazonses.com.


Re: [Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-05-12 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
 Reporter:  Mathieu Kniewallner  |Owner:  Mariusz
 |  Felisiak
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * needs_better_patch:  1 => 0
 * owner:  Mathieu Kniewallner => Mariusz Felisiak

Comment:

 [https://github.com/django/django/pull/18160 PR]
-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f6e6c292c-5352dbe2-bb28-4cc3-9e0e-72fed5b33080-00%40eu-central-1.amazonses.com.


Re: [Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-03-06 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
 Reporter:  Mathieu Kniewallner  |Owner:  Mathieu
 |  Kniewallner
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  1
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * needs_better_patch:  0 => 1

-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e154ffd3a-f662749b-9c7d-4912-b113-ad6a58f07abb-00%40eu-central-1.amazonses.com.


Re: [Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-03-06 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
 Reporter:  Mathieu Kniewallner  |Owner:  Mathieu
 |  Kniewallner
 Type:  Bug  |   Status:  assigned
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mathieu Kniewallner):

 * has_patch:  0 => 1
 * owner:  nobody => Mathieu Kniewallner
 * status:  new => assigned

-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e14da7422-36b6a58e-e7d8-4510-8d6a-78dd7c7a38e8-00%40eu-central-1.amazonses.com.


Re: [Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-03-06 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
 Reporter:  Mathieu Kniewallner  |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Mariusz Felisiak):

 * cc: Gagaro (added)
 * stage:  Unreviewed => Accepted

Comment:

 Good catch, thanks for the report. Please prepare a patch via GitHub PR (a
 regression test is required).
-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e149ae6c8-dd02cd0d-f90e-45df-889b-f1d673bb4401-00%40eu-central-1.amazonses.com.


[Django] #35275: Constraints validation fails on UniqueConstraint using OpClass

2024-03-06 Thread Django
#35275: Constraints validation fails on UniqueConstraint using OpClass
-+-
   Reporter:  Mathieu|  Owner:  nobody
  Kniewallner|
   Type:  Bug| Status:  new
  Component:  Database   |Version:  dev
  layer (models, ORM)|
   Severity:  Normal |   Keywords:
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 Adding a `UniqueConstraint` using PostgreSQL-specific `OpClass` on a model
 breaks constraints validation performed when calling
 `validate_constraints` on a model when using PostgreSQL.

 === Minimal reproducer
 {{{#!python
 from django.contrib.postgres.indexes import OpClass
 from django.db import models
 from django.db.models.functions import Lower


 class Place(models.Model):
 name = models.CharField(max_length=255)

 class Meta:
 app_label = "opclass_issue"
 constraints = [
 models.UniqueConstraint(
 OpClass(Lower("name"), name="text_pattern_ops"),
 name="lower_name_uniq",
 )
 ]


 place = Place(name="Narnia")
 place.validate_constraints()
 }}}

 This leads to the following error:
 {{{
 django.db.utils.ProgrammingError: syntax error at or near
 "text_pattern_ops"
 LINE 1: ...place" WHERE LOWER("opclass_issue_place"."name") text_patte...
 }}}

 Full SQL query that is generated:
 {{{#!sql
 SELECT 1 AS "a" FROM "opclass_issue_place" WHERE
 LOWER("opclass_issue_place"."name") text_pattern_ops = (LOWER('narnia')
 text_pattern_ops) LIMIT 1
 }}}

 Just in case, this happens even though `django.contrib.postgres` is
 correctly installed in `INSTALLED_APPS`, so the issue is not related to
 that.

 I've also created a test and adapted the CI to run it in
 https://github.com/backmarket-oss/django/pull/2/files, which leads to
 https://github.com/backmarket-
 oss/django/actions/runs/8171237603/job/22339033423?pr=2 showing the
 failure.

 === Potential root cause

 `OpClass` wrapper should only make sense when creating the constraint, and
 should not be used when validating the constraint, as this leads to an
 invalid SQL query.

 Looking at the code for the PostgreSQL specific `ExclusionConstraint`, a
 similar conclusion was reached, and `OpClass` is explicitly removed in
 `validate` method:
 
https://github.com/django/django/blob/4426b1a72dc289643e2ae8c190b8dc4b3a39daf7/django/contrib/postgres/constraints.py#L211-L216.

 === Potential fix

 Applying a similar fix as the one above in `UniqueConstraint`, showcased
 in https://github.com/backmarket-oss/django/pull/1/files applied on top of
 the other PR above, leads to https://github.com/backmarket-
 oss/django/actions/runs/8171242801/job/22339050847?pr=1 where the added
 test is now passing.

 If you think that this is the correct fix to apply, or have a lead for
 another fix, I'd be happy to make a proper pull request targeting Django
 repository.
-- 
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e13ca0979-fa582a9e-c0cb-4892-9842-97c8207da856-00%40eu-central-1.amazonses.com.