@@ -25,37 +25,38 @@ class Undefined:
25
25
26
26
27
27
_ModelT = TypeVar ("_ModelT" , bound = models .Model )
28
+ _unspecified = object ()
28
29
29
30
30
31
def bulk_create (
31
32
db_model : type [_ModelT ],
32
33
objs : Iterable [_ModelT ],
33
34
* ,
34
- batch_size : int | None = ... ,
35
- ignore_conflicts : bool = ... ,
36
- update_conflicts : bool | None = ... ,
37
- update_fields : Sequence [str ] | None = ... ,
38
- unique_fields : Sequence [str ] | None = ... ,
35
+ batch_size : int | None = _unspecified ,
36
+ ignore_conflicts : bool = False ,
37
+ update_conflicts : bool | None = False ,
38
+ update_fields : Sequence [str ] | None = None ,
39
+ unique_fields : Sequence [str ] | None = None ,
39
40
) -> list [_ModelT ]:
40
- "Like Django's Model.objects.bulk_create(), but applies the default batch size"
41
+ """
42
+ Like Django's Model.objects.bulk_create(), but applies the default batch size configured by
43
+ the DEFAULT_DB_BULK_CREATE_BATCH_SIZE setting.
44
+ """
41
45
42
- if batch_size is Ellipsis :
46
+ if batch_size is _unspecified :
43
47
batch_size = settings .DEFAULT_DB_BULK_CREATE_BATCH_SIZE
44
48
45
- kwargs = {}
46
- for k , v in {
47
- "ignore_conflicts" : ignore_conflicts ,
48
- "update_conflicts" : update_conflicts ,
49
- "update_fields" : update_fields ,
50
- "unique_fields" : unique_fields ,
51
- }.items ():
52
- if v is not Ellipsis :
53
- kwargs [k ] = v
54
-
55
49
if not objs :
56
50
return []
57
51
58
- return db_model .objects .bulk_create (objs , batch_size = batch_size , ** kwargs )
52
+ return db_model .objects .bulk_create (
53
+ objs ,
54
+ batch_size = batch_size ,
55
+ ignore_conflicts = ignore_conflicts ,
56
+ update_conflicts = update_conflicts ,
57
+ update_fields = update_fields ,
58
+ unique_fields = unique_fields ,
59
+ )
59
60
60
61
61
62
def is_prefetched (queryset : models .QuerySet , field : str ) -> bool :
0 commit comments