Procházet zdrojové kódy

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

* Deepcopy should not cause a recursion error on the ProductAttributesContainer
master
Voxin Muyli před 2 roky
rodič
revize
c4ebfa680f
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 3
- 0
src/oscar/apps/catalogue/product_attributes.py Zobrazit soubor

@@ -16,6 +16,9 @@ class ProductAttributesContainer:
16 16
     """
17 17
 
18 18
     def __setstate__(self, state):
19
+        self.__dict__.setdefault("_product", None)
20
+        self.__dict__.setdefault("_initialized", False)
21
+        self.__dict__.setdefault("_dirty", set())
19 22
         self.__dict__ = state
20 23
 
21 24
     def __init__(self, product):

+ 7
- 0
tests/unit/catalogue/test_product_attributes.py Zobrazit soubor

@@ -1,3 +1,5 @@
1
+from copy import deepcopy
2
+
1 3
 from django.core.exceptions import ValidationError
2 4
 from django.test import TestCase
3 5
 
@@ -167,6 +169,11 @@ class ProductAttributeTest(TestCase):
167 169
             "so it saved, even when the parent has the same value",
168 170
         )
169 171
 
172
+    def test_deepcopy(self):
173
+        "Deepcopy should not cause a recursion error"
174
+        deepcopy(self.product)
175
+        deepcopy(self.child_product)
176
+
170 177
 
171 178
 class ProductAttributeQuerysetTest(TestCase):
172 179
     fixtures = ["productattributes"]

Načítá se…
Zrušit
Uložit