return error data when using only() and select_related() at the same times that models foreign key is set to default null.
>>> from station.models import Station_Building
>>> s1=Station_Building.objects.select_related('building').only('azimuth','building__level').filter(building__isnull=False)
>>> s1[0].building.level
0 #wrong value
>>> s1=Station_Building.objects.select_related('building').filter(building__isnull=False)
>>> s1[0].building.level
1 #right value
>>>
Change History
(6)
Triage Stage: |
Unreviewed → Accepted
|
Cc: |
buburno+django@… added
|
Resolution: |
→ duplicate
|
Status: |
new → closed
|
I have tried to look at this without success. It seems that the generated SQL is perfectly fine but some columns get mixed when building the python representation.
I have some models that looks like this:
If I do:
then:
So, the problem may not be specific to foreign keys, and the engine fetches information from wrong related tables.
This happens at least on PostgreSQL, I can't confirm on other backends.