Skip to content

Commit

Permalink
feat ⭐ return valid resources after full clean
Browse files Browse the repository at this point in the history
  • Loading branch information
samar-hassan committed Aug 26, 2024
1 parent 77debb1 commit 01da495
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oscar_odin/mappings/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def products_to_db(
After that all the products will be bulk saved.
At last all related models like images, stockrecords, and related_products can will be saved and set on the product.
"""
errors = validate_resources(products)
_, errors = validate_resources(products)
if errors:
return [], errors
instances, context = products_to_model(
Expand Down
4 changes: 3 additions & 1 deletion oscar_odin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def querycounter(*labels, print_queries=False):

def validate_resources(resources):
errors = []
valid_resources = []
if not resources:
return
if not isinstance(resources, (list, tuple)):
Expand All @@ -87,6 +88,7 @@ def validate_resources(resources):
for resource in resources:
try:
resource.full_clean()
valid_resources.append(resource)
except ValidationError as error:
errors.append(error)
return errors
return valid_resources, errors

0 comments on commit 01da495

Please sign in to comment.