소스 검색

Fixes broken migration of attribute values

Currently _get_value calls other model properties which are not defined on the historical model.
Replace usage of historical model with a helper function
master
Lars van de Kerkhof 1 년 전
부모
커밋
dd5bb502f1
1개의 변경된 파일11개의 추가작업 그리고 9개의 파일을 삭제
  1. 11
    9
      src/oscar/apps/catalogue/migrations/0024_remove_duplicate_attributes.py

+ 11
- 9
src/oscar/apps/catalogue/migrations/0024_remove_duplicate_attributes.py 파일 보기

@@ -5,15 +5,17 @@ from django.db import migrations
5 5
 from django.db.models import CharField, Count, Value
6 6
 from django.db.models.functions import Concat
7 7
 
8
-from oscar.core.loading import get_model
9
-
10
-# Needed for calling _get_value, the historical model can't be used for that.
11
-NonHistoricalProductAttributeValue = get_model('catalogue', 'ProductAttributeValue')
12
-
13
-
14 8
 logger = logging.getLogger(__name__)
15 9
 
16 10
 
11
+def get_value(attribute_value):
12
+    typ = attribute_value.attribute.type
13
+    field_name = "value_%s" % typ
14
+    value = getattr(attribute_value, field_name)
15
+    if hasattr(value, "all"):
16
+        value = value.all()
17
+    return value
18
+
17 19
 def remove_duplicate_attributes(apps, schema_editor):
18 20
     """
19 21
     Removes duplicate attributes that have the same code and product class.
@@ -83,8 +85,8 @@ def remove_duplicate_attributes(apps, schema_editor):
83 85
                     """ % (
84 86
                         product.id,
85 87
                         attribute.code,
86
-                        NonHistoricalProductAttributeValue._get_value(to_be_used_attribute_value),
87
-                        NonHistoricalProductAttributeValue._get_value(attribute_value)
88
+                        get_value(to_be_used_attribute_value),
89
+                        get_value(attribute_value)
88 90
                     )
89 91
                     logger.warning(msg)
90 92
 
@@ -101,4 +103,4 @@ class Migration(migrations.Migration):
101 103
 
102 104
     operations = [
103 105
         migrations.RunPython(remove_duplicate_attributes, migrations.RunPython.noop)
104
-    ]
106
+    ]

Loading…
취소
저장