Skip to content

Commit 22e96cd

Browse files
authored
Merge pull request #23 from maxipavlovic/bugfix-2/LITE-17616
LITE-17616 Fixed `cqrs.bulk_create` output: returns a list of created objects
2 parents 7267329 + 54d337b commit 22e96cd

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

dj_cqrs/managers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def bulk_create(self, objs, **kwargs):
2828
model = type(objs[0])
2929
model.call_post_bulk_create(objs, using=self.db)
3030

31+
return objs
32+
3133
def bulk_update(self, queryset, **kwargs):
3234
""" Custom update method to support sending of update signals.
3335

integration_tests/tests/test_asynchronous_consuming.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ def test_both_consumers_consume(settings, replica_cursor, clean_rabbit_transport
1515
assert count_replica_rows(replica_cursor, REPLICA_BASIC_TABLE) == 0
1616
assert count_replica_rows(replica_cursor, REPLICA_EVENT_TABLE) == 0
1717

18-
master_instances = BasicFieldsModel.objects.bulk_create([
18+
BasicFieldsModel.cqrs.bulk_create([
1919
BasicFieldsModel(
2020
int_field=index,
2121
char_field='text',
2222
)
2323
for index in range(1, 10)
2424
])
25-
BasicFieldsModel.call_post_bulk_create(master_instances)
2625

2726
transport_delay(5)
2827
assert count_replica_rows(replica_cursor, REPLICA_BASIC_TABLE) == 9

tests/test_master/test_signals.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,17 @@ def test_manual_post_bulk_create(mocker):
7171
def test_automatic_post_bulk_create(mocker):
7272
publisher_mock = mocker.patch('dj_cqrs.controller.producer.produce')
7373

74-
models.SimplestTrackedModel.cqrs.bulk_create([
74+
instances = models.SimplestTrackedModel.cqrs.bulk_create([
7575
models.SimplestTrackedModel(id=i, status='new') for i in range(1, 4)
7676
])
7777

78+
assert len(instances) == 3
79+
for index in range(3):
80+
instance = instances[index]
81+
assert instance.id == index + 1
82+
assert instance.status == 'new'
83+
assert instance.cqrs_revision == 0
84+
7885
assert publisher_mock.call_count == 3
7986

8087
for index, call in enumerate(publisher_mock.call_args_list, start=1):

0 commit comments

Comments
 (0)