﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34594	KT doesn’t work across foreign keys	Roman Odaisky	nobody	"Assuming
{{{
class Parent(Model):
    data = JSONField()

class Child(Model):
    parent = ForeignKey(Parent)
}}}
the expressions
{{{
Parent.objects.annotate(x=F(""data__some_string"")).first().x
Parent.objects.annotate(x=KT(""data__some_string"")).first().x
Parent.objects.first().data[""some_string""]
}}}
all return the same value. So far, so good. However, in the following F works but KT doesn’t:
{{{
Child.objects.annotate(x=F(""parent__data__some_string""))
Child.objects.annotate(x=KT(""parent__data__some_string""))
}}}
The problem is in the SQL that KT generates: `(""parent"".""id"" #>> ARRAY['data','some_string']) AS ""x""`, which, it seems, is the result of KeyTextTransform.from_lookup taking all the double-underscore-separated parts of the argument of KT to mean JSON lookups and not other possible lookups such as foreign keys.

Please fix by using the same mechanisms F uses in this case."	New feature	closed	Database layer (models, ORM)	4.2	Normal	wontfix			Unreviewed	0	0	0	0	0	0
