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

Deepcopy should not cause a recursion error on the ProductAttributesC… #4018

Merged
merged 2 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/oscar/apps/catalogue/product_attributes.py
Expand Up @@ -16,6 +16,9 @@ class ProductAttributesContainer:
"""

def __setstate__(self, state):
self.__dict__.setdefault("_product", None)
self.__dict__.setdefault("_initialized", False)
self.__dict__.setdefault("_dirty", set())
self.__dict__ = state

def __init__(self, product):
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/catalogue/test_product_attributes.py
@@ -1,3 +1,5 @@
from copy import deepcopy

from django.core.exceptions import ValidationError
from django.test import TestCase

Expand Down Expand Up @@ -167,6 +169,11 @@ def test_explicit_identical_child_attribute(self):
"so it saved, even when the parent has the same value",
)

def test_deepcopy(self):
"Deepcopy should not cause a recursion error"
deepcopy(self.product)
deepcopy(self.child_product)


class ProductAttributeQuerysetTest(TestCase):
fixtures = ["productattributes"]
Expand Down