#34149: Postgres "ExclusionConstraint with conditions cannot be deferred." seems
wrong
--------------------------------------------+------------------------
               Reporter:  Márton Salomváry  |          Owner:  (none)
                   Type:  Bug               |         Status:  new
              Component:  contrib.postgres  |        Version:  4.1
               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                 |
--------------------------------------------+------------------------
 When attempting to add a constraint to a model that looks something like
 this:


 {{{
 ExclusionConstraint(
                 name="my_constraint",
                 expressions=[
                     ("is_default", RangeOperators.EQUAL),
                 ],
                 condition=Q(is_default=False),
                 deferrable=Deferrable.DEFERRED,
             )
 }}}

 `makemigrations` fails with the following error:


 {{{

     ExclusionConstraint(
   File "django/contrib/postgres/constraints.py", line 55, in __init__
     raise ValueError("ExclusionConstraint with conditions cannot be
 deferred.")
 ValueError: ExclusionConstraint with conditions cannot be deferred.
 }}}

 However PostgreSQL 14.5 seems to be perfectly fine with the following:


 {{{
 ALTER TABLE my_model
     ADD CONSTRAINT my_constraint
         EXCLUDE (is_default WITH =)
         WHERE (is_default = TRUE)
         INITIALLY DEFERRED;
 }}}

 I've tried to figure out why this restriction may be in place but neither
 other parts of Django nor PostgreSQL itself seem to require deferred
 exclusion constraints to not have a condition.

 The commit that added this also does not seem to explain the situation:
 
https://github.com/django/django/commit/b4068bc65636cca6c2905aa8c40bea69bb0e4245

 Maybe an accidental copypaste from here?
 
https://github.com/django/django/blob/35911078fa40eb35859832987fedada76963c01e/django/db/models/constraints.py#L153-L154

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34149>
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/010701845d79df83-6ef37158-89b8-4034-afe9-013b26e01345-000000%40eu-central-1.amazonses.com.

Reply via email to