Opened 19 months ago
Closed 16 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)
follow-up: 2 comment:1 by , 19 months ago
| Summary: | FieldError: Unsupported lookup error message can be confusing on DateTimeField → FieldError: Unsupported lookup error message can be confusing. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → Cleanup/optimization |
comment:2 by , 18 months ago
Replying to Sarah Boyce:
Replicated, this is also true of other fields.
I agree that saying something likeUnsupported lookup 'gt__foo',Unsupported lookup 'gt__', andUnsupported 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 wether name is needed or not. Thoughts?
comment:4 by , 17 months ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 17 months ago
| Has patch: | set |
|---|
comment:7 by , 16 months ago
| Patch needs improvement: | set |
|---|
comment:8 by , 16 months ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Replicated, this is also true of other fields.
I agree that saying something like
Unsupported lookup 'gt__foo',Unsupported lookup 'gt__', andUnsupported lookup 'gt__lt'would be clearer.