diff --git a/oscar_odin/mappings/catalogue.py b/oscar_odin/mappings/catalogue.py index 2791c63..47cc407 100644 --- a/oscar_odin/mappings/catalogue.py +++ b/oscar_odin/mappings/catalogue.py @@ -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( diff --git a/oscar_odin/utils.py b/oscar_odin/utils.py index 9ae3de0..b29b7f9 100644 --- a/oscar_odin/utils.py +++ b/oscar_odin/utils.py @@ -77,8 +77,9 @@ def querycounter(*labels, print_queries=False): def validate_resources(resources): errors = [] + valid_resources = [] if not resources: - return + return [], [] if not isinstance(resources, (list, tuple)): if isinstance(resources, MappingResult): resources = resources.items @@ -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