Wednesday, September 23, 2020

select_for_update + select_related issue

Hello.
I just wanted to know, whether I run into a bug, and whether I should report it.

Normally select_for_update and select_related try to lock all affected rows in all tables. One can specify "of" for select_for_update to limit tables to lock (to prevent locking nullable relations).

Recently a bug was fixed, which allowed to lock parent nodes with multitable inheritance. But what about proxies? For me the following does not work. Should it?

class Parent(Model):
  foreign = ForeignKey(Foreign, null=True, blank=True)

class Child(Parent):
  class Meta:
    proxy = True

class Foreign(Model):
  pass

with transaction.atomic():
  Child.objects.select_for_update(of=('self',)).select_related('foreign').get(pk=1)

So the (pseudo) code above fails with a message "FOR UPDATE cannot be applied to the nullable side of an outer join"

So is this expected behaviour or a bug? What are possible workarounds for that?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b19cde81-9fb2-4226-bd24-74509b894e79n%40googlegroups.com.

No comments:

Post a Comment