Opened 4 years ago

Closed 4 years ago

#31874 closed Bug (worksforme)

FK id is not used in update_or_create when id is not used directly

Reported by: Erki Bender Owned by: nobody
Component: Database layer (models, ORM) Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

Let's say you have a table

class Foo(models.Model):
    obj = models.ForeignKey('Bar', on_delete=models.CASCADE)
    x = model.IntegerField()
    y = model.CharField(length=10)
    class Meta:
        unique_together = ('obj', 'x')

When you use Foo.objects.update_or_create(obj=instance, x=1, defaults={'y': 'test'}), the SQL generated will omit the obj_id from WHERE clause. On the other hand, when obj_id=10 is used, it is used in WHERE clause.

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Description: modified (diff)
Resolution: worksforme
Status: newclosed

Thanks for the report, however I cannot reproduce described issue.

Note: See TracTickets for help on using tickets.
Back to Top