File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1923,37 +1923,32 @@ def _batched_insert(
19231923 max_batch_size = max (ops .bulk_batch_size (fields , objs ), 1 )
19241924 batch_size = min (batch_size , max_batch_size ) if batch_size else max_batch_size
19251925 inserted_rows = []
1926- bulk_return = connection .features .can_return_rows_from_bulk_insert
1926+ returning_fields = (
1927+ self .model ._meta .db_returning_fields
1928+ if (
1929+ connection .features .can_return_rows_from_bulk_insert
1930+ and (on_conflict is None or on_conflict == OnConflict .UPDATE )
1931+ )
1932+ else None
1933+ )
19271934 batches = [objs [i : i + batch_size ] for i in range (0 , len (objs ), batch_size )]
19281935 if len (batches ) > 1 :
19291936 context = transaction .atomic (using = self .db , savepoint = False )
19301937 else :
19311938 context = nullcontext ()
19321939 with context :
19331940 for item in batches :
1934- if bulk_return and (
1935- on_conflict is None or on_conflict == OnConflict .UPDATE
1936- ):
1937- inserted_rows .extend (
1938- self ._insert (
1939- item ,
1940- fields = fields ,
1941- using = self .db ,
1942- on_conflict = on_conflict ,
1943- update_fields = update_fields ,
1944- unique_fields = unique_fields ,
1945- returning_fields = self .model ._meta .db_returning_fields ,
1946- )
1947- )
1948- else :
1941+ inserted_rows .extend (
19491942 self ._insert (
19501943 item ,
19511944 fields = fields ,
19521945 using = self .db ,
19531946 on_conflict = on_conflict ,
19541947 update_fields = update_fields ,
19551948 unique_fields = unique_fields ,
1949+ returning_fields = returning_fields ,
19561950 )
1951+ )
19571952 return inserted_rows
19581953
19591954 def _chain (self ):
You can’t perform that action at this time.
0 commit comments