Model.validate_unique method doesn't take in account multi-db
|Reported by:||Tetsuya Morimoto||Owned by:|
|Component:||Database layer (models, ORM)||Version:||1.2|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Model.validate_unique() method has 2 methods, _perform_unique_checks() and _perform_date_checks(), which use _default_manager for queryset. But, they are not considered with multi-db, that queryset is as follows.
qs = model_class._default_manager.filter(**lookup_kwargs)
I encountered a problem when ModelForm.is_valid() method is called since BaseModelForm calls full_clean() -> post_clean() -> validate_unique(). I could add/change/delete data with multi-db in AdminSite by setting arbitrary database with "using" keyword. However, the validation uniqueness check is invalid if default database has the same data.
I only tested default table operation in AdminSite applying attached patch.
It works for me.
Change History (32)
comment:5 Changed 6 years ago by
|Status:||new → closed|
|Summary:||Model.validate_unique method is not considered with multi-db → Model.validate_unique method doesn't take in account multi-db|
comment:15 Changed 6 years ago by
|Component:||ORM aggregation → Database layer (models, ORM)|