You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Duplicated models do not retain the same database as the original, if the original database is not the default.
To Reproduce
Steps to reproduce the behavior:
With settings that include a router that determines database from request (ie, models are not linked to specific database), call make_clone on an instance that is from a non-default database. The clone will be created in the default database, not the same database as the original instance.
Expected behavior
The clone should be created in the same database as the original instance.
Screenshots
Desktop (please complete the following information):
OS: Windows Server 2016
Version v2.5.3
Additional context
I got it working (basic testing) correctly by changing make_clone duplicate.save to:
db = self._state.db
duplicate.save(using=db)
and for create_copy_of_instance:
db = instance._state.db
new_obj = instance.__class__.objects.using(db).create(**defaults)
The text was updated successfully, but these errors were encountered:
Describe the bug
Duplicated models do not retain the same database as the original, if the original database is not the default.
To Reproduce
Steps to reproduce the behavior:
With settings that include a router that determines database from request (ie, models are not linked to specific database), call make_clone on an instance that is from a non-default database. The clone will be created in the default database, not the same database as the original instance.
Expected behavior
The clone should be created in the same database as the original instance.
Screenshots
Desktop (please complete the following information):
Additional context
I got it working (basic testing) correctly by changing make_clone duplicate.save to:
and for create_copy_of_instance:
The text was updated successfully, but these errors were encountered: