Skip to content

Commit a1646d8

Browse files
authored
Merge pull request #4 from jokiefer/bugfix/#3-None-valued-id
fixes #3
2 parents f799a93 + 4cce1d1 commit a1646d8

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99

10+
[0.3.1] - 2024-10-17
11+
--------------------
12+
13+
Fixed
14+
~~~~~
15+
* None valued ids on bulk add handling
16+
17+
1018
[0.3.0] - 2023-07-10
1119
--------------------
1220

atomic_operations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"
22
VERSION = __version__ # synonym

atomic_operations/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ def perform_bulk_create(self, bulk_operation_data):
109109
_serializer.is_valid(raise_exception=True)
110110
instance = model_class(**_serializer.validated_data)
111111
objs.append(instance)
112-
self.response_data.append(
113-
_serializer.__class__(instance=instance).data)
114112
model_class.objects.bulk_create(
115113
objs)
114+
# append serialized data after save has successfully called. Otherwise id could be None. See #3
115+
self.response_data.extend(
116+
[_serializer.__class__(instance=obj).data for obj in objs])
116117

117118
def perform_bulk_delete(self, bulk_operation_data):
118119
obj_ids = []

tests/test_views.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22

3+
from django import VERSION
34
from django.test import Client, RequestFactory, TestCase
45

56
from atomic_operations.consts import (
@@ -195,8 +196,15 @@ def test_view_processing_with_valid_request(self):
195196

196197
self.assertEqual(RelatedModel.objects.get(pk=1),
197198
BasicModel.objects.get(pk=2).to_one)
198-
self.assertQuerysetEqual(RelatedModelTwo.objects.filter(pk__in=[1, 2]),
199-
BasicModel.objects.get(pk=2).to_many.all())
199+
200+
major, minor, _, _, _ = VERSION
201+
if int(major) <= 4 and int(minor) <= 1:
202+
self.assertQuerysetEqual(RelatedModelTwo.objects.filter(pk__in=[1, 2]),
203+
BasicModel.objects.get(pk=2).to_many.all())
204+
else:
205+
# with django 4.2 TransactionTestCase.assertQuerysetEqual() is deprecated in favor of assertQuerySetEqual().
206+
self.assertQuerySetEqual(RelatedModelTwo.objects.filter(pk__in=[1, 2]),
207+
BasicModel.objects.get(pk=2).to_many.all())
200208

201209
def test_bulk_view_processing_with_valid_request(self):
202210
operations = [

0 commit comments

Comments
 (0)