Skip to content

Using pk to set the value of a primary key using on_conflict does not work #24

@Photonios

Description

@Photonios
class MyModel(PostgresModel):
    myfield = models.CharField(max_length=255)

obj1 = (
    MyModel.objects
    .on_conflict(['pk'], ConflictAction.UPDATE)
    .insert_and_get(pk=0, myfield='beer')
)

obj2 = (
    MyModel.objects
    .on_conflict(['pk'], ConflictAction.UPDATE)
    .insert_and_get(pk=0, myfield='beer')
)

assert obj1.id == obj2.id

The following example does not work. This is because pk refers to the a models.AutoField, which django-postgres-extra does special logic for. However, it should be possible to override the default value. In the example above, you should end up with 1 row with id=0. However, instead, you end up with to rows with id=1 and id=2.

This is closely related to #23.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions