File tree 2 files changed +15
-6
lines changed 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,12 @@ def bulk_insert(
139
139
the models of the rows inserted with defaults for any fields not specified
140
140
"""
141
141
142
+ def is_empty (r ):
143
+ return all ([False for _ in r ])
144
+
145
+ if not rows or is_empty (rows ):
146
+ return []
147
+
142
148
if not self .conflict_target and not self .conflict_action :
143
149
# no special action required, use the standard Django bulk_create(..)
144
150
return super ().bulk_create (
@@ -375,12 +381,6 @@ def bulk_upsert(
375
381
the models of the rows upserted
376
382
"""
377
383
378
- def is_empty (r ):
379
- return all ([False for _ in r ])
380
-
381
- if not rows or is_empty (rows ):
382
- return []
383
-
384
384
self .on_conflict (
385
385
conflict_target ,
386
386
ConflictAction .UPDATE ,
Original file line number Diff line number Diff line change 7
7
8
8
from psqlextra .expressions import ExcludedCol
9
9
from psqlextra .fields import HStoreField
10
+ from psqlextra .query import ConflictAction
10
11
11
12
from .fake_model import get_fake_model
12
13
@@ -245,10 +246,18 @@ def test_upsert_bulk_no_rows():
245
246
{"name" : models .CharField (max_length = 255 , null = True , unique = True )}
246
247
)
247
248
249
+ model .objects .on_conflict (ConflictAction .UPDATE , ["name" ]).bulk_insert (
250
+ rows = []
251
+ )
252
+
248
253
model .objects .bulk_upsert (conflict_target = ["name" ], rows = [])
249
254
250
255
model .objects .bulk_upsert (conflict_target = ["name" ], rows = None )
251
256
257
+ model .objects .on_conflict (ConflictAction .UPDATE , ["name" ]).bulk_insert (
258
+ rows = None
259
+ )
260
+
252
261
253
262
def test_bulk_upsert_return_models ():
254
263
"""Tests whether models are returned instead of dictionaries when
You can’t perform that action at this time.
0 commit comments