File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,12 @@ def bulk_insert(
139139 the models of the rows inserted with defaults for any fields not specified
140140 """
141141
142+ def is_empty (r ):
143+ return all ([False for _ in r ])
144+
145+ if not rows or is_empty (rows ):
146+ return []
147+
142148 if not self .conflict_target and not self .conflict_action :
143149 # no special action required, use the standard Django bulk_create(..)
144150 return super ().bulk_create (
@@ -375,12 +381,6 @@ def bulk_upsert(
375381 the models of the rows upserted
376382 """
377383
378- def is_empty (r ):
379- return all ([False for _ in r ])
380-
381- if not rows or is_empty (rows ):
382- return []
383-
384384 self .on_conflict (
385385 conflict_target ,
386386 ConflictAction .UPDATE ,
Original file line number Diff line number Diff line change 77
88from psqlextra .expressions import ExcludedCol
99from psqlextra .fields import HStoreField
10+ from psqlextra .query import ConflictAction
1011
1112from .fake_model import get_fake_model
1213
@@ -245,10 +246,18 @@ def test_upsert_bulk_no_rows():
245246 {"name" : models .CharField (max_length = 255 , null = True , unique = True )}
246247 )
247248
249+ model .objects .on_conflict (ConflictAction .UPDATE , ["name" ]).bulk_insert (
250+ rows = []
251+ )
252+
248253 model .objects .bulk_upsert (conflict_target = ["name" ], rows = [])
249254
250255 model .objects .bulk_upsert (conflict_target = ["name" ], rows = None )
251256
257+ model .objects .on_conflict (ConflictAction .UPDATE , ["name" ]).bulk_insert (
258+ rows = None
259+ )
260+
252261
253262def test_bulk_upsert_return_models ():
254263 """Tests whether models are returned instead of dictionaries when
You can’t perform that action at this time.
0 commit comments