File tree Expand file tree Collapse file tree 3 files changed +12
-0
lines changed Expand file tree Collapse file tree 3 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,7 @@ def _get_model_field(self, name: str):
219
219
# key of a model, we have to respect this de-facto standard behaviour
220
220
if field_name == 'pk' and self .query .model ._meta .pk :
221
221
return self .query .model ._meta .pk
222
+
222
223
for field in self .query .model ._meta .local_concrete_fields :
223
224
if field .name == field_name or field .column == field_name :
224
225
return field
Original file line number Diff line number Diff line change @@ -328,6 +328,14 @@ def _get_upsert_fields(self, kwargs):
328
328
update_fields .append (field )
329
329
continue
330
330
331
+ # special handling for 'pk' which always refers to
332
+ # the primary key, so if we the user specifies `pk`
333
+ # instead of a concrete field, we have to handle that
334
+ if field .primary_key is True and 'pk' in kwargs :
335
+ insert_fields .append (field )
336
+ update_fields .append (field )
337
+ continue
338
+
331
339
if self ._is_magical_field (model_instance , field , is_insert = True ):
332
340
insert_fields .append (field )
333
341
Original file line number Diff line number Diff line change @@ -330,3 +330,6 @@ def test_on_conflict_pk_conflict_target(conflict_action):
330
330
331
331
assert obj1 .name == 'beer'
332
332
assert obj2 .name == 'beer'
333
+ assert obj1 .id == obj2 .id
334
+ assert obj1 .id == 0
335
+ assert obj2 .id == 0
You can’t perform that action at this time.
0 commit comments