Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#31538 closed Bug (fixed)

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

Reported by: Simon Meers Owned by: felixxm
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 Changed 5 months ago by felixxm

Cc: Hasan Ramezani added
Owner: changed from nobody to felixxm
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 Changed 5 months ago by felixxm

Has patch: set

comment:3 Changed 5 months ago by GitHub <noreply@…>

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 Changed 5 months ago by Mariusz Felisiak <felisiak.mariusz@…>

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