Opened 4 years ago

Last modified 4 years ago

#31874 closed Bug

FK id is not used in update_or_create when id is not used directly — at Initial Version

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

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 (0)

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