Opened 8 years ago

Closed 8 years ago

#27268 closed Bug (fixed)

Regression on error message for invalid related fields lookup in QuerySet.get()

Reported by: François Freitag Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: get lookup related fields
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The expected error message for an invalid lookup in a get() operation shoud look like:

Related Field got invalid lookup: foo

The current error message is:

TypeError: 'NoneType' object is not callable

Steps to reproduce:
models.py

class Tag(models.Model):
    text = models.CharField(max_length=100, unique=True)

class Thing(models.Model):
    name = models.CharField(max_length=100)
    tags = models.ManyToManyField(Tag)

tests.py

def test_invalid_lookup(self):
    with self.assertRaisesMessage(TypeError, "Related Field got invalid lookup"):
        Thing.objects.get(tags__foo='bar')

It seems that the regression is introduced by https://github.com/django/django/commit/7aeb7390fc4231119494a9ebdee3c6ee0d5af053 and is only present on master.

Trac ticket related to the commit introducing the regression: https://code.djangoproject.com/ticket/26891

Change History (4)

comment:1 by Simon Charette, 8 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Mariusz Felisiak, 8 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 by Tim Graham, 8 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 14986a0:

Fixed #27268 -- Restored an invalid related field lookup error message in QuerySet filtering.

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