diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5276992..10fbf29 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +[0.3.1] - 2024-10-17 +-------------------- + +Fixed +~~~~~ +* None valued ids on bulk add handling + + [0.3.0] - 2023-07-10 -------------------- diff --git a/atomic_operations/__init__.py b/atomic_operations/__init__.py index 0e54ddc..5873c76 100644 --- a/atomic_operations/__init__.py +++ b/atomic_operations/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.3.0" +__version__ = "0.3.1" VERSION = __version__ # synonym diff --git a/atomic_operations/views.py b/atomic_operations/views.py index 8d1a439..9eec1b1 100644 --- a/atomic_operations/views.py +++ b/atomic_operations/views.py @@ -109,10 +109,11 @@ def perform_bulk_create(self, bulk_operation_data): _serializer.is_valid(raise_exception=True) instance = model_class(**_serializer.validated_data) objs.append(instance) - self.response_data.append( - _serializer.__class__(instance=instance).data) model_class.objects.bulk_create( objs) + # append serialized data after save has successfully called. Otherwise id could be None. See #3 + self.response_data.extend( + [_serializer.__class__(instance=obj).data for obj in objs]) def perform_bulk_delete(self, bulk_operation_data): obj_ids = [] diff --git a/tests/test_views.py b/tests/test_views.py index 8b11ab2..83ce388 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,5 +1,6 @@ import json +from django import VERSION from django.test import Client, RequestFactory, TestCase from atomic_operations.consts import ( @@ -195,8 +196,15 @@ def test_view_processing_with_valid_request(self): self.assertEqual(RelatedModel.objects.get(pk=1), BasicModel.objects.get(pk=2).to_one) - self.assertQuerysetEqual(RelatedModelTwo.objects.filter(pk__in=[1, 2]), - BasicModel.objects.get(pk=2).to_many.all()) + + major, minor, _, _, _ = VERSION + if int(major) <= 4 and int(minor) <= 1: + self.assertQuerysetEqual(RelatedModelTwo.objects.filter(pk__in=[1, 2]), + BasicModel.objects.get(pk=2).to_many.all()) + else: + # with django 4.2 TransactionTestCase.assertQuerysetEqual() is deprecated in favor of assertQuerySetEqual(). + self.assertQuerySetEqual(RelatedModelTwo.objects.filter(pk__in=[1, 2]), + BasicModel.objects.get(pk=2).to_many.all()) def test_bulk_view_processing_with_valid_request(self): operations = [