diff --git a/oscar_odin/mappings/utils.py b/oscar_odin/mappings/utils.py index f2c4655..90d3dd7 100644 --- a/oscar_odin/mappings/utils.py +++ b/oscar_odin/mappings/utils.py @@ -115,32 +115,32 @@ def save_many_to_many(context, errors): def save_attributes(instances): + attributes_to_update = [] attributes_to_create = [] attributes_to_delete = [] - attributes_to_update = [] fields_to_be_updated = set() for product in instances: product.attr.invalidate() ( - to_be_deleted, - update_fields, to_be_updated, to_be_created, + to_be_deleted, + update_fields, ) = product.attr.prepare_save() - if to_be_deleted: - attributes_to_delete.extend(to_be_deleted) - - if update_fields: - fields_to_be_updated.update(update_fields) - if to_be_updated: attributes_to_update.extend(to_be_updated) if to_be_created: attributes_to_create.extend(to_be_created) + if to_be_deleted: + attributes_to_delete.extend(to_be_deleted) + + if update_fields: + fields_to_be_updated.update(update_fields) + # now save all the attributes in bulk if attributes_to_delete: ProductAttributeValue.objects.filter(pk__in=attributes_to_delete).delete() diff --git a/tests/mappings/test_catalogue.py b/tests/mappings/test_catalogue.py index 6891ff1..ca6734c 100644 --- a/tests/mappings/test_catalogue.py +++ b/tests/mappings/test_catalogue.py @@ -31,4 +31,3 @@ def test_product_to_resource__where_is_a_parent_product_do_not_include_children( actual = catalogue.product_to_resource(product) self.assertEqual(product.title, actual.title) - self.assertIsNone(actual.children)