#32635: System checks for invalid model field names in
CheckConstraint.check/UniqueConstraint.condition crash with a reverse 020
relation.
-------------------------------------+-------------------------------------
     Reporter:  sim1234              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:  UniqueConstraint     |             Triage Stage:  Accepted
  OneToOneField                      |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * cc: Hasan Ramezani (added)
 * version:  2.2 => 3.2
 * severity:  Normal => Release blocker


Comment:

 System checks for invalid model field names in `CheckConstraint.check` and
 `UniqueConstraint.condition`, added in
 b7b7df5fbcf44e6598396905136cab5a19e9faff, crash for me with a reverse 020
 relation, e.g.

 {{{
 diff --git a/tests/invalid_models_tests/test_models.py
 b/tests/invalid_models_tests/test_models.py
 index c79684487d..f39e424251 100644
 --- a/tests/invalid_models_tests/test_models.py
 +++ b/tests/invalid_models_tests/test_models.py
 @@ -1694,6 +1694,25 @@ class ConstraintsTests(TestCase):
              ),
          ])

 +    @skipUnlessDBFeature('supports_table_check_constraints')
 +    def test_check_constraint_pointing_to_reverse_o2o(self):
 +        class Model(models.Model):
 +            parent = models.OneToOneField('self', models.CASCADE,
 related_name='model')
 +
 +            class Meta:
 +                constraints = [
 +                    models.CheckConstraint(name='name',
 check=models.Q(model__isnull=True)),
 +                ]
 +
 +        self.assertEqual(Model.check(databases=self.databases), [
 +            Error(
 +                "'constraints' refers to the nonexistent field 'model'.",
 +                obj=Model,
 +                id='models.E012',
 +            ),
 +        ])
 +
 }}}

 {{{
   File "django/django/db/models/base.py", line 1296, in check
     *cls._check_constraints(databases),
   File "django/django/db/models/base.py", line 2108, in _check_constraints
     field.get_transform(first_lookup) is None and
 AttributeError: 'OneToOneRel' object has no attribute 'get_transform'
 }}}

 Marking as a release blocker since it's a bug in a new feature.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32635#comment:2>
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/065.7a3737f91e8ad269c3891d824f846571%40djangoproject.com.

Reply via email to