#31874: FK id is not used in update_or_create when id is not used directly
-------------------------------------+-------------------------------------
Reporter: Erki Bender | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):
* status: new => closed
* resolution: => worksforme
Old 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.
New 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.
--
Comment:
Thanks for the report, however I cannot reproduce described issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/31874#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.7da128059cbdabc8f3a84d976375b60b%40djangoproject.com.