From 4569ac260e32500a92153afb008c4c41934af637 Mon Sep 17 00:00:00 2001 From: Viggo de Vries Date: Fri, 26 Jan 2024 11:42:07 +0100 Subject: [PATCH] Move check to the saving part of the products. This will make it possible to use other parts of this package without having to use django 4 or postgres --- oscar_odin/apps.py | 3 --- oscar_odin/checks.py | 23 ----------------------- oscar_odin/mappings/context.py | 10 +++++++++- 3 files changed, 9 insertions(+), 27 deletions(-) delete mode 100644 oscar_odin/checks.py diff --git a/oscar_odin/apps.py b/oscar_odin/apps.py index 34bb116..5325649 100644 --- a/oscar_odin/apps.py +++ b/oscar_odin/apps.py @@ -18,6 +18,3 @@ def ready(self): # Register the Django model field resolver registration.register_field_resolver(ModelFieldResolver, Model) - - # pylint: disable=W0611 - from .checks import odin_startup_check diff --git a/oscar_odin/checks.py b/oscar_odin/checks.py deleted file mode 100644 index b5a6a99..0000000 --- a/oscar_odin/checks.py +++ /dev/null @@ -1,23 +0,0 @@ -from django import VERSION -from django.core.checks import Error, register, Tags -from django.conf import settings - - -# pylint: disable=unused-argument -@register(Tags.compatibility) -def odin_startup_check(app_configs, **kwargs): - errors = [] - - django_major_version = VERSION[0] - - if django_major_version < 4: - for _, database in settings.DATABASES.items(): - if database["ENGINE"] == "django.db.backends.sqlite3": - errors.append( - Error( - "django-oscar-odin does not support sqlite3 with Django < 4. Please use engines that have can_return_rows_from_bulk_insert set to True (like Postgres) or upgrade your Django version to 4 or higher.", - id="django-oscar-odin.E001", - ) - ) - - return errors diff --git a/oscar_odin/mappings/context.py b/oscar_odin/mappings/context.py index fb44545..98ad2ba 100644 --- a/oscar_odin/mappings/context.py +++ b/oscar_odin/mappings/context.py @@ -173,12 +173,20 @@ def bulk_update_or_create_foreign_keys(self): Model.objects.bulk_update(instances, fields=fields) def bulk_update_or_create_instances(self, instances): - instances_to_create, instances_to_update = separate_instances_to_create_and_update( + ( + instances_to_create, + instances_to_update, + ) = separate_instances_to_create_and_update( self.Model, instances, self.identifier_mapping ) validated_create_instances = self.validate_instances(instances_to_create) self.Model.objects.bulk_create(validated_create_instances) + for instance in validated_create_instances: + if instance.pk is None: + raise OscarOdinException( + "django-oscar-odin does not support sqlite3 with Django < 4. Please use engines that have can_return_rows_from_bulk_insert set to True (like Postgres) or upgrade your Django version to 4 or higher." + ) fields = self.get_fields_to_update(self.Model) if fields is not None: