Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29679 closed Bug (needsinfo)

select_related() crashes with "ORA-00918: column ambiguously defined" on Oracle

Reported by: zap_kid Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords: orm, oracle, select_related
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Suppose I have ModelA and ModelB where ModelA has a ForeignKey field model_b with ModelB and in addition ModelA and ModelB share another non-foreign key field with the same name. Then ModelA.objects.filter(...).select_related('model_b') throws django.db.utils.DatabaseError: ORA-00918: column ambiguously defined even though Django is generating the correct SQL. See https://stackoverflow.com/questions/51879477/django-2-1-and-select-related

discovered using Oracle 12C and Python 3.6

Change History (4)

comment:1 by Tim Graham, 6 years ago

I can't reproduce the crash. I tried:

ModelA.objects.filter(example_field=1).select_related('modelB_field')

which gives this query:

SELECT "BASIC_MODELA"."ID", "BASIC_MODELA"."MODELB_FIELD_ID", "BASIC_MODELA"."EXAMPLE_FIELD", "BASIC_MODELB"."ID", "BASIC_MODELB"."EXAMPLE_FIELD" 
FROM "BASIC_MODELA" INNER JOIN "BASIC_MODELB" ON ("BASIC_MODELA"."MODELB_FIELD_ID" = "BASIC_MODELB"."ID")
WHERE "BASIC_MODELA"."EXAMPLE_FIELD" = 1

Can you give more precise steps to reproduce? Ideally, you could also bisect to find the commit where the behavior changed.

comment:2 by Tim Graham, 6 years ago

Summary: select_related not working as expected with Oracle 12C and Python 3.6select_related() crashes with "ORA-00918: column ambiguously defined" on Oracle

comment:3 by Tim Graham, 6 years ago

Resolution: needsinfo
Status: newclosed

in reply to:  1 comment:4 by zap_kid, 6 years ago

Thanks for taking a look. I made a dummy project and can't reproduce it either. Something else is going on in my project. I'll keep digging.
Replying to Tim Graham:

I can't reproduce the crash. I tried:

ModelA.objects.filter(example_field=1).select_related('modelB_field')

which gives this query:

SELECT "BASIC_MODELA"."ID", "BASIC_MODELA"."MODELB_FIELD_ID", "BASIC_MODELA"."EXAMPLE_FIELD", "BASIC_MODELB"."ID", "BASIC_MODELB"."EXAMPLE_FIELD" 
FROM "BASIC_MODELA" INNER JOIN "BASIC_MODELB" ON ("BASIC_MODELA"."MODELB_FIELD_ID" = "BASIC_MODELB"."ID")
WHERE "BASIC_MODELA"."EXAMPLE_FIELD" = 1

Can you give more precise steps to reproduce? Ideally, you could also bisect to find the commit where the behavior changed.

Note: See TracTickets for help on using tickets.
Back to Top