Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31538 closed Bug (fixed)

models.E015 is raised when ordering uses lookups that are not transforms.

Reported by: Simon Meers Owned by: Mariusz Felisiak
Component: Core (System checks) Version: 3.0
Severity: Release blocker Keywords:
Cc: Hasan Ramezani Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

./manage.py check
SystemCheckError: System check identified some issues:
ERRORS:

app.Stock: (models.E015) 'ordering' refers to the nonexistent field, related field, or lookup 'supply__product__parent__isnull'.

However this ordering works fine:

>>> list(Stock.objects.order_by('supply__product__parent__isnull').values_list('pk', flat=True)[:5])
[1292, 1293, 1300, 1295, 1294]
>>> list(Stock.objects.order_by('-supply__product__parent__isnull').values_list('pk', flat=True)[:5])
[108, 109, 110, 23, 107]

I believe it was fine until #29408 was implemented.

Stock.supply is a foreign key to Supply, Supply.product is a foreign key to Product, Product.parent is a ForeignKey('self', models.CASCADE, null=True)

Change History (4)

comment:1 by Mariusz Felisiak, 4 years ago

Cc: Hasan Ramezani added
Owner: changed from nobody to Mariusz Felisiak
Severity: NormalRelease blocker
Status: newassigned
Summary: Django 3.0 raises invalid models.E015 check errormodels.E015 is raised when ordering uses lookups that are not transforms.
Triage Stage: UnreviewedAccepted

Thanks for the report, it's related with using lookup that are not transforms, e.g. isnull

    def test_ordering_pointing_to_lookup_not_transform(self):
        class Model(models.Model):
            test = models.CharField(max_length=100)
            
            class Meta:
                ordering = ('test__isnull',)
                
        self.assertEqual(Model.check(), [])

Regression in 440505cb2cadbe1a5b9fba246bcde6c04f51d07e.

comment:2 by Mariusz Felisiak, 4 years ago

Has patch: set

comment:3 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In b73e66e:

Fixed #31538 -- Fixed Meta.ordering validation lookups that are not transforms.

Regression in 440505cb2cadbe1a5b9fba246bcde6c04f51d07e.

Thanks Simon Meers for the report.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In fdd5eb43:

[3.0.x] Fixed #31538 -- Fixed Meta.ordering validation lookups that are not transforms.

Regression in 440505cb2cadbe1a5b9fba246bcde6c04f51d07e.

Thanks Simon Meers for the report.
Backport of b73e66e75802f10cc34d4880714554cea54dbf49 from master

Note: See TracTickets for help on using tickets.
Back to Top