Opened 4 years ago

Closed 4 years ago

#32321 closed Cleanup/optimization (fixed)

Add system checks for invalid model field names for functional indexes in Meta.indexes.

Reported by: Mariusz Felisiak Owned by: Hasan Ramezani
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.

Attachments (1)

tests_32321.diff (3.2 KB ) - added by Mariusz Felisiak 4 years ago.
Tests.

Download all attachments as: .zip

Change History (6)

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.

comment:3 by Hasan Ramezani, 4 years ago

Triage Stage: Someday/MaybeAccepted

comment:4 by Hasan Ramezani, 4 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In f750377:

Fixed #32321 -- Added system checks for invalid model field names in functional indexes.

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