From afaed5fc450b3399808097d0811c7d3c8f23cb51 Mon Sep 17 00:00:00 2001 From: Samar Hassan <88422175+samar-hassan@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:01:31 +0100 Subject: [PATCH] feat :star: return valid resources after full clean (#35) --- oscar_odin/mappings/catalogue.py | 2 +- oscar_odin/utils.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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..7c206fd 100644 --- a/oscar_odin/utils.py +++ b/oscar_odin/utils.py @@ -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)): @@ -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