﻿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
20487	oracle: case mixup causes ORA-00918: column ambiguously defined error	Charlie.Tang@…	Shai Berger	"a model's fields, which have a common related model, led to the issue.

Here is an example:

{{{
class Institution(models.Model):
    name = models.CharField('full name', max_length=50)

class Personel(models.Model):
    institution = models.ForeignKey(Institution)

class Protocol(models.Model):
    Institution = models.ForeignKey('Institution', blank=True, null=True)

class StudyAssignment(models.Model):
    personel = models.ForeignKey(Personel)
    protocol = models.ForeignKey(Protocol)
}}}


which generated sql


{{{
SELECT * 
FROM 
(   SELECT ROWNUM AS ""_RN"", ""_SUB"".* 
    FROM 
    (   SELECT ""STUDY_ASSIGNMENT"".""ID"", ""STUDY_ASSIGNMENT"".""PERSONEL_ID"", ""STUDY_ASSIGNMENT"".""PROTOCOL_ID"", ""PERSONEL"".""ID"" AS Col3
              , ""PERSONEL"".""INSTITUTION_ID""
              , ""INSTITUTION"".""ID"" AS Col5, ""INSTITUTION"".""NAME"", ""PROTOCOL"".""ID"" AS Col7
              , ""PROTOCOL"".""INSTITUTION_ID""
              , T5.""ID"" AS Col9, T5.""NAME"" AS Col10 
        FROM ""STUDY_ASSIGNMENT"" 
              INNER JOIN ""PERSONEL"" ON (""STUDY_ASSIGNMENT"".""PERSONEL_ID"" = ""PERSONEL"".""ID"") 
              INNER JOIN ""INSTITUTION"" ON (""PERSONEL"".""INSTITUTION_ID"" = ""INSTITUTION"".""ID"") 
              INNER JOIN ""PROTOCOL"" ON (""STUDY_ASSIGNMENT"".""PROTOCOL_ID"" = ""PROTOCOL"".""ID"") 
            INNER JOIN ""INSTITUTION"" T5 ON (""PROTOCOL"".""INSTITUTION_ID"" = T5.""ID"") 
        ORDER BY ""STUDY_ASSIGNMENT"".""ID"" DESC
    ) ""_SUB""
    WHERE ROWNUM <= 21
)
WHERE ""_RN"" > 0;
}}}

To call model StudyAssignment through django admin. Both '''""PERSONEL"".""INSTITUTION_ID""''''''' and '''""PROTOCOL"".""INSTITUTION_ID""''' led to the issue.
"	Bug	closed	Database layer (models, ORM)	1.5	Normal	fixed	oracle ORA-00918	shai@… carsten.fuchs@…	Ready for checkin	0	0	0	0	0	0
