Code

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#14466 closed (invalid)

"ORA-00918: column ambiguously defined error" has reappeared in 1.2.3

Reported by: biolsen Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords: Oracle, column ambiguously defined
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

It seems that the ORA-00918 error, regarding identical column names in multiple tables (where aliases are necessary for instance in nested result sets like SELECT * FROM (SELECT .. FROM ...) ), somehow has been reintroduced into the code since its resolution in ticked #7057.

The following patch has resolved the issue in 1.2.3 (solution based on ticked #7057).

In /django/db/models/sql/compiler.py:

--- 71,88 ----
          result = ['SELECT']
          if self.query.distinct: 
              result.append('DISTINCT') 
+         # Below is a patch to the 1.2.3 code that, at least with Oracle 
+         # made selects with identical column names crash with a ambiguous 
+         # column name error. This error was corrected in previous versions
+         # of Django, but seemed to be re-introduced with 1.2.3. 
+         if ordering: 
+             cols = [clause.split('.')[-1] for clause in out_cols] 
+             for index, col in enumerate(cols): 
+                 if cols.count(col) > 1: 
+                     col = '%s%d' % (col.replace('"', ''), index) 
+                     cols[index] = col 
+                     out_cols[index] = '%s AS %s' % (out_cols[index], col) 
          result.append(', '.join(out_cols + self.query.ordering_aliases)) 
          result.append('FROM') 
          result.extend(from_) 
          params.extend(f_params) 
*************** 

Attachments (0)

Change History (4)

comment:1 Changed 4 years ago by biolsen

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by ikelly

  • Needs tests set

Please provide a specific test case that demonstrates the error. The select_related test case from #7057 works properly for me in 1.2.3, as well as in trunk and the 1.2.X branch.

comment:3 Changed 3 years ago by russellm

  • Resolution set to invalid
  • Status changed from new to closed

Closing invalid; Ian can't reproduce, and the reporter hasn't responded to a request for more info. Please reopen if you can provide a reproducible test case.

comment:4 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.