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] duplicate functional -> duplicate records #672

Closed
3 tasks done
accedx opened this issue Oct 31, 2022 · 0 comments · Fixed by #673
Closed
3 tasks done

[BUG] duplicate functional -> duplicate records #672

accedx opened this issue Oct 31, 2022 · 0 comments · Fixed by #673
Labels
bug Something isn't working

Comments

@accedx
Copy link

accedx commented Oct 31, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

This block is a duplicate functionality of the functions __duplicate_m2o_fields and __duplicate_o2m_fields.
And does not use _clone_m2o_or_o2m_fields.
As a result, additional copies of records appear.

I propose a solution - remove this block:

            if (f.many_to_one or f.one_to_many) and instance._state.db != using:
                sub_instance = getattr(instance, f.name, None) or f.get_default()

                if sub_instance is not None:
                    sub_instance = CloneMixin._create_copy_of_instance(
                        sub_instance,
                        force=True,
                        sub_clone=True,
                        using=using,
                    )
                    sub_instance.save(using=using)
                    value = sub_instance.pk

To Reproduce

class Item(Model, CloneMixin):
    pass

class ModelName(Model, CloneMixin):
    items = ForeignKey(Item)

    _clone_m2o_or_o2m_fields = ['item']

ModelName.objects.using('db-id-1').get(pk=1).make_clone(using=DEFAULT_DB_ALIAS)

What OS are you seeing the problem on?

No response

Expected behavior?

Don't create additional copies of records

Relevant log output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@accedx accedx added the bug Something isn't working label Oct 31, 2022
@jackton1 jackton1 linked a pull request Nov 1, 2022 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.

1 participant