Skip to content

Commit 9c7c587

Browse files
committed
feat ⭐ make upc optional for product's related models
1 parent 333197f commit 9c7c587

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

oscar_odin/mappings/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ def bulk_update_or_create_many_to_many(self):
408408
# Instead of failing bulk_create here below, we will add an error.
409409
self.errors.add_error(
410410
OscarOdinException(
411-
{Through.__name__: f"Cannot create m2m relationship {Through.__name__} - related model '{relation.related_model.__name__}' is missing a primary key"}
411+
{
412+
Through.__name__: f"Cannot create m2m relationship {Through.__name__} - related model '{relation.related_model.__name__}' is missing a primary key"
413+
}
412414
),
413415
instance,
414416
)

oscar_odin/resources/catalogue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ class ProductAttributeValueResource(OscarCatalogueResource):
8989

9090

9191
class ParentProductResource(OscarCatalogueResource):
92-
upc: str
92+
upc: Optional[str]
9393

9494

9595
class ProductRecommentationResource(OscarCatalogueResource):
96-
upc: str
96+
upc: Optional[str]
9797

9898

9999
class ProductResource(OscarCatalogueResource):

tests/reverse/test_catalogue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def test_recommendation_non_existing(self):
677677
_, errors = products_to_db(product_resource)
678678
self.assertEqual(len(errors), 1)
679679
self.assertEqual(
680-
str(errors[0]),
680+
str(errors[0].args[0]["ProductRecommendation"]),
681681
"Cannot create m2m relationship ProductRecommendation - related model 'Product' is missing a primary key",
682682
)
683683

0 commit comments

Comments
 (0)