Opened 4 years ago

Last modified 4 years ago

#32321 closed Cleanup/optimization

Add system checks for invalid model field names for functional indexes in Meta.indexes. — at Version 2

Reported by: Mariusz Felisiak Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords:
Cc: Hannes Ljungberg Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

The current system checks don't cover invalid models fields in functional indexes. This is not straightforward because resolving expressions with non-existent throws FieldError, so we cannot just collect columns from Query._gen_cols().

Follow up to #26167.

I attached tests.

Change History (3)

by Mariusz Felisiak, 4 years ago

Attachment: tests_32321.diff added

Tests.

comment:1 by Hasan Ramezani, 4 years ago

Mariusz,
When I try to run the tests that you added to the ticket, I get

ValueError('Index.fields must be a list or tuple.')

it means currently, models.Index doesn't support models.F('height') / (models.F('weight__abs') + models.Value(5)) and Lower('missing_field').desc() as index fields.

Should we add support for these kinds of fields to models.Index?

comment:2 by Mariusz Felisiak, 4 years ago

Description: modified (diff)
Triage Stage: AcceptedSomeday/Maybe

Sorry Hasan, I should mark this ticket as "someday", it's a follow up to #26167. It will be valid after merging PR.

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