{{{
class MyModel(models.Model):
my_unique = models.IntegerField(unique=True)
obj = MyModel(my_unique=value_exists_on_default_new_on_other_connection)
obj._state.db = other_connection
obj.full_clean()
# for existing objects _state.db will be already set
obj = MyModel.objects.using(other_connection).get(pk=existing)
obj.my_unique = value_exists_on_default_new_on_other_connection
obj.full_clean()
}}}
`full_clean()` will `validate_unique()` -> `_perform_unique_checks()`,
which will eventually `qs =
model_class._default_manager.filter(**lookup_kwargs)`. The default manager
is always using default connection, so unique check will be performed on
default connection. Other validators, such as ForeignKey lookup, properly
use `.using()` to keep talking to the database where the object came from.
Fix: {{{ qs =
model_class._default_manager.filter(**lookup_kwargs).using(self._state.db)
}}}
The same fix is needed for `_perform_date_checks()`.
--
Ticket URL: <https://code.djangoproject.com/ticket/20301>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/20301#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #15130
--
Ticket URL: <https://code.djangoproject.com/ticket/20301#comment:2>