#31415: Nested OuterRefs produce error when used as argument to Left
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
BurningLights |
Type: | Status: new
Uncategorized |
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Given the following contrived set of models and the latest Django 3.0.5:
{{{
class Node(models.Model):
steplen = 4
path = models.CharField(max_length=100)
class NodeAttribute(models.Model):
node = models.ForeignKey(Node, on_delete=models.CASCADE)
attribute_name = models.CharField(max_length=64)
attribute_value = models.CharField(max_length=64)
class Entity(models.Model):
name = models.CharField(max_length=64)
age = models.IntegerField()
class EntityNode(models.Model):
entity = models.ForeignKey(Entity, on_delete=models.CASCADE)
node = models.ForeignKey(Node, on_delete=models.CASCADE)
role = models.CharField(max_length=64)
}}}
The query
{{{
NodeAttribute.objects.annotate(
test=Subquery(Entity.objects.filter(
entitynode__node__nodeattribute__attribute_name=OuterRef('attribute_name'),
name=Subquery(EntityNode.objects.filter(
node__path=Left(OuterRef(OuterRef('node__path')), Node.steplen
* 2)
).values('entity__name')[:1])
).values('age')[:1])
)
}}}
produces the exception "AttributeError: 'OuterRef' object has no attribute
'relabeled_clone'."
The problem is with using nested OuterRefs as a parameter to Left. I have
not had any trouble with using a single OuterRef with SQL functions, but
trying to go up two levels with nested OuterRefs does not appear to work.
Please note that the above models and query are for illustrative purposes
only and represent the simplest example of the problem I could come up
with.
--
Ticket URL: <https://code.djangoproject.com/ticket/31415>
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/056.8aed6292fc254d0686588f69c7f69332%40djangoproject.com.