Skip to content

Commit

Permalink
Deepcopy should not cause a recursion error on the ProductAttributesC… (
Browse files Browse the repository at this point in the history
#4018)

* Deepcopy should not cause a recursion error on the ProductAttributesContainer
  • Loading branch information
specialunderwear committed Dec 1, 2022
1 parent 44ce5c3 commit c4ebfa6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit c4ebfa6

Please sign in to comment.