Opened 7 weeks ago

Last modified 3 weeks ago

#35413 new Cleanup/optimization

FieldError: Unsupported lookup error message can be confusing.

Reported by: Alex Owned by: nobody
Component: Database layer (models, ORM) Version: 5.0
Severity: Normal Keywords:
Cc: Alex Triage Stage: Accepted
Has patch: no 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 (2)

comment:1 by Sarah Boyce, 7 weeks 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, 3 weeks 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 in django/db/models/sql/query.py, 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?
BTW, I can handle it.

Last edited 3 weeks ago by Amir Karimi (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top