From 178fa79425a295f71f45f8fbd8b2a1c863d177c6 Mon Sep 17 00:00:00 2001 From: Samar Hassan <88422175+samar-hassan@users.noreply.github.com> Date: Fri, 26 Jan 2024 09:52:03 +0000 Subject: [PATCH] [Fix] Resolve product class updating to None in Django 3.2 (#12) * fix :bug: resolve product class updating to None in django 3.2 * refactor :package: use existing method from base.Model --- oscar_odin/mappings/context.py | 3 +++ oscar_odin/utils.py | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/oscar_odin/mappings/context.py b/oscar_odin/mappings/context.py index c498e75..1ed2b39 100644 --- a/oscar_odin/mappings/context.py +++ b/oscar_odin/mappings/context.py @@ -182,6 +182,9 @@ def bulk_update_or_create_instances(self, instances): fields = self.get_fields_to_update(self.Model) if fields is not None: + for instance in instances_to_update: + # This should be removed once support for django 3.2 is dropped + instance._prepare_related_fields_for_save("bulk_update") self.Model.objects.bulk_update(instances_to_update, fields=fields) def bulk_update_or_create_one_to_many(self): diff --git a/oscar_odin/utils.py b/oscar_odin/utils.py index 861172a..951af03 100644 --- a/oscar_odin/utils.py +++ b/oscar_odin/utils.py @@ -1,13 +1,10 @@ +from collections import defaultdict import contextlib import time import math -from django.db import connection, reset_queries - -from collections import defaultdict - -from django.db.models import Model, ManyToManyField, ForeignKey, Q -from django.db import connections +from django.db import connection, connections, reset_queries +from django.db.models import Q def get_filters(instances, field_names):