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 — at Version 1
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 )
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 , 4 years ago
Description: | modified (diff) |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Thanks for the report, however I cannot reproduce described issue.