Opened 7 years ago

Closed 7 years ago

#28707 closed Bug (duplicate)

Model.validate_unique() method doesn't take in account multi-db

Reported by: coulix Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords: multidb admin uniqueness
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In a multi-db configuration it seems that constraints such as model field unique=True does always target the default db in the Django admin. It ignores the MultiDBModelAdmin way as explained here https://docs.djangoproject.com/en/1.11/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface.

Digging a bit I see the _perform_unique_checks method here that does not seem to be able to take an other db connection than the default.

https://github.com/django/django/blob/fb02ebe889eee292144f9157ed4ddcdcc139eba9/django/db/models/base.py#L1005

 qs = model_class._default_manager.filter(**lookup_kwargs)

For now I am going to use my own validator on save but either I am doing it wrong or there is a bug / doc update that needs attention.

Change History (1)

comment:1 by Tim Graham, 7 years ago

Easy pickings: unset
Resolution: duplicate
Status: newclosed
Summary: multidb admin uniqueness issue - No way to make the django admin perform unique checks on non default db.Model.validate_unique() method doesn't take in account multi-db

Duplicate of #15130.

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