#30350: CheckConstraint repeatedly deleted and re-added
-------------------------------------+-------------------------------------
               Reporter:  Sigurd     |          Owner:  nobody
  Ljødal                             |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.2
  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          |
-------------------------------------+-------------------------------------
 A `CheckConstraint` with a `Q(x__in=range(y, z))` condition is repeatedly
 deleted and re-added when running `makemigrations`.


 {{{#!python
 models.CheckConstraint(
     check=models.Q(month__in=range(1, 13)),
     name='check_valid_month',
 )
 }}}

 The generated migration looks like this, so I suspect that the issue is
 because the range is converted into a tuple:

 {{{#!python
     operations = [
         migrations.RemoveConstraint(
             model_name='monthlybudget',
             name='check_valid_month',
         ),
         migrations.AddConstraint(
             model_name='monthlybudget',
             constraint=models.CheckConstraint(check=models.Q(month__in=(1,
 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), name='check_valid_month'),
         ),
     ]
 }}}

 A sample project with this issue can be found here:
 https://github.com/ljodal/djangocon-eu-2019

 I'm open to fixing this issue myself, but I would like to clarify what
 would be a correct fix to this issue. I see at least two possible
 solutions, maybe three:
  1. Keep the `range` method call in the generated migration file
  2. Disallow using ranges in check constraints
  3. (At least on PostgreSQL, we could use a range expression in the
 database too.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30350>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.869621f7e9db131f2118867e64583915%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to