Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Duplicated models are not always created in same database #366

Closed
NodeJSmith opened this issue Jun 18, 2021 · 1 comment · Fixed by #368
Closed

[BUG] - Duplicated models are not always created in same database #366

NodeJSmith opened this issue Jun 18, 2021 · 1 comment · Fixed by #368
Labels
bug Something isn't working

Comments

@NodeJSmith
Copy link

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
2021-06-18 10_35_52-Remote Desktop Manager Free  cls-md-dbwebdv1
2021-06-18 10_38_00-Remote Desktop Manager Free  cls-md-dbwebdv1

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)
@NodeJSmith NodeJSmith added the bug Something isn't working label Jun 18, 2021
@jackton1 jackton1 linked a pull request Jun 19, 2021 that will close this issue
@jackton1
Copy link
Member

Thanks @NodeJSmith the latest v2.6.x version should include the bug fix.

Also Thanks for coffee.

@jackton1 jackton1 linked a pull request Jun 24, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants