Opened 8 months ago

Closed 6 months ago

#35413 closed Cleanup/optimization (fixed)

FieldError: Unsupported lookup error message can be confusing.

Reported by: Alex Owned by: wookkl
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords:
Cc: Alex 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

On these example queries on DateTimeFields:

TestModel.objects.filter(created_at__gt__foo='2024-01-01')
TestModel.objects.filter(created_at__gt__='2024-01-01')  # I'm a bit surprised this one also has the same message.
TestModel.objects.filter(created_at__gt__lt='2024-01-01')

The error message is this

django.core.exceptions.FieldError: Unsupported lookup 'gt' for DateTimeField or join on the field not permitted, perhaps you meant gt or gte?

The error message should clarify better the issue.

Change History (9)

comment:1 by Sarah Boyce, 8 months ago

Summary: FieldError: Unsupported lookup error message can be confusing on DateTimeFieldFieldError: Unsupported lookup error message can be confusing.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Replicated, this is also true of other fields.
I agree that saying something like Unsupported lookup 'gt__foo', Unsupported lookup 'gt__', and Unsupported lookup 'gt__lt' would be clearer.

in reply to:  1 comment:2 by Amir Karimi, 7 months ago

Replying to Sarah Boyce:

Replicated, this is also true of other fields.
I agree that saying something like Unsupported lookup 'gt__foo', Unsupported lookup 'gt__', and Unsupported lookup 'gt__lt' would be clearer.

If we just pass down LOOKUP_SEP.join(arg.split(LOOKUP_SEP)[1:]) to the build_lookup method, it can print out the input lookup entirely. It outputs'gt__foo', 'gt__' , and 'gt__lt' .

It can be an argument to the try_transform method. Not sure whether name is needed or not. Thoughts?

Version 1, edited 7 months ago by Amir Karimi (previous) (next) (diff)

comment:3 by wookkl, 6 months ago

Can I resolve this issue?

Last edited 6 months ago by wookkl (previous) (diff)

comment:4 by wookkl, 6 months ago

Owner: changed from nobody to wookkl
Status: newassigned

comment:5 by wookkl, 6 months ago

Has patch: set

comment:7 by Sarah Boyce, 6 months ago

Patch needs improvement: set

comment:8 by Sarah Boyce, 6 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by Sarah Boyce <42296566+sarahboyce@…>, 6 months ago

Resolution: fixed
Status: assignedclosed

In 759abc4d:

Fixed #35413 -- Made unsupported lookup error message more specific.

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