Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tools to track which fields_to_update after mapping. #55

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

specialunderwear
Copy link
Member

It would be nice if we could find out for mapper what the exact data it is that they are mapping to.

The util get_mapped_fields can be used to check which field the mapper will actually update on the to_obj

products_to_db accepts the fields_to_update parameter to do partial updates.

We can now use a combination of get_mapped_fields and ProductToModel.get_fields_impacted_by_mapping to check which fields are actually updated on the product model through a chain of mappings.

>>>     mapper = SomeMapperMappingToProductResource
>>>     mapped_fields = get_mapped_fields(mapper)
>>>     mapped_fields
{'upc', 'vat_rate', 'product_class', 'structure', 'price', 'title', 'partner'}
>>>     ProductToModel.get_fields_impacted_by_mapping(*mapped_fields)
['Product.upc', 'StockRecord.partner_sku', 'StockRecord.partner', 'ProductClass.slug', 'StockRecord.price', 'StockRecord.price_currency', 'Product.structure', 'Product.title']

The output can be directly passed to products_to_db as the fields_to_update parameter

@@ -17,6 +17,7 @@
PRODUCT_META_TITLE = "Product.meta_title"
PRODUCT_META_DESCRIPTION = "Product.meta_description"
PRODUCT_IS_DISCOUNTABLE = "Product.is_discountable"
PRODUCT_PRIORITY = "Product.priority"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have priority field for product model?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

@@ -55,7 +56,7 @@
PRODUCT_META_TITLE,
PRODUCT_META_DESCRIPTION,
PRODUCT_IS_DISCOUNTABLE,
PRODUCT_PARENT,
PRODUCT_PRIORITY,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to remove parent field from this list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in this list twice

product_to_model_fields = get_mapped_fields(catalogue.ProductToModel)
self.assertListEqual(
sorted(product_to_model_fields),
[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe define this list in a variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this is a test so ...

@samar-hassan samar-hassan merged commit f84a049 into master Nov 29, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants