django-partial-index icon indicating copy to clipboard operation
django-partial-index copied to clipboard

validate_partial_unique does not check inherited indexes

Open levic opened this issue 5 years ago • 1 comments

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.

https://github.com/mattiaslinnap/django-partial-index/blob/a5ddf7a4db9391ec55096fd98e87f4d5b3d6360e/partial_index/mixins.py#L58

levic avatar Apr 08 '19 08:04 levic

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 avatar Apr 10 '19 01:04 levic