Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate_partial_unique does not check inherited indexes #18

Open
levic opened this issue Apr 8, 2019 · 1 comment
Open

validate_partial_unique does not check inherited indexes #18

levic opened this issue Apr 8, 2019 · 1 comment

Comments

@levic
Copy link

levic commented Apr 8, 2019

If you use multi-table inheritance then validate_partial_unique() doesn't work if Meta is overridden by the child; any uniqueness constraints on the parent model will be ignored even though they are present in the database.

unique_idxs = [idx for idx in self._meta.indexes if isinstance(idx, PartialIndex) and idx.unique]

@levic
Copy link
Author

levic commented Apr 10, 2019

For reference:

Django's validate_unique() traverses the MRO and appends parent indexes to the list of unique indexes to check.

In 2.2 (when django added native support for partial indexes), validate_unique() didn't change, but _get_unique_checks gives up entirely on trying to validate the constraints ("Partial unique constraints can't be validated")

In other words, there's no forward compatibility to be aware of, but traversing the Meta classes in the MRO is consistent with existing django behaviour for non-partial uniqueness.

@levic levic mentioned this issue May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant