Opened 11 years ago

Closed 6 years ago

#20487 closed Bug (fixed)

oracle: case mixup causes ORA-00918: column ambiguously defined error

Reported by: Charlie.Tang@… Owned by: Shai Berger
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords: oracle ORA-00918
Cc: shai@…, carsten.fuchs@… Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Attachments (1)

20487.diff (3.6 KB ) - added by Mariusz Felisiak 6 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Charlie.Tang@…, 11 years ago

Fixed the issues through changing the field name Institution of class Protocol to lower case

comment:2 by anonymous, 11 years ago

Resolution: fixed
Status: newclosed

comment:3 by Shai Berger, 11 years ago

Resolution: fixed
Status: closednew

comment:4 by Shai Berger, 11 years ago

Cc: shai@… added
Keywords: oracle added
Owner: changed from nobody to Shai Berger
Status: newassigned
Summary: ORA-00918: column ambiguously defined errororacle: case mixup causes ORA-00918: column ambiguously defined error
Triage Stage: UnreviewedAccepted

comment:5 by Carsten Fuchs, 9 years ago

Cc: carsten.fuchs@… added

comment:6 by Mariusz Felisiak, 6 years ago

I couldn't reproduce this issue on stable/1.7.x -> master. I think we can add a test and close this ticket.

by Mariusz Felisiak, 6 years ago

Attachment: 20487.diff added

comment:7 by Mariusz Felisiak, 6 years ago

PR with test.

comment:8 by Shai Berger, 6 years ago

Triage Stage: AcceptedReady for checkin

Added some cosmetic comments on the PR, but it's mostly good to go.

comment:9 by GitHub <noreply@…>, 6 years ago

In aad1833f:

Refs #20487 -- Added test for querying mixed case fields with common related model.

Thanks Shai Berger for the review.

comment:10 by Mariusz Felisiak, 6 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top