Opened 7 years ago

Closed 7 years ago

#28206 closed Bug (fixed)

Raw queries with Oracle impossible when using uppercase column names

Reported by: Dmitry Shachnev Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: Oracle
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When one has a model with a custom column name in uppercase, say:

class Man(Model):
    id = models.AutoField(primary_key=True, db_column="F_MAN_ID")

Then it is impossible to use RawQuerySets with this model on Oracle, you will always get the “InvalidQuery: Raw query must include the primary key” error.

The problem is that column_name_converter() converts the column names to lowercase, so even if you use F_MAN_ID in your query, the self.columns list in the RawQuerySet instance will contain the lowercase column name. And because of case differences the f.column in self.columns check in resolve_model_init_order method will return False.

We are currently using Django 1.8 in production, but I looked at the Django code and it’s the same between 1.8 and 1.11, so I have put 1.11 into the Version field.

Attachments (1)

28206.diff (456 bytes ) - added by Mariusz Felisiak 7 years ago.
Test

Download all attachments as: .zip

Change History (6)

by Mariusz Felisiak, 7 years ago

Attachment: 28206.diff added

Test

comment:1 by Mariusz Felisiak, 7 years ago

Keywords: Oracle added
Triage Stage: UnreviewedAccepted
Version: 1.11master

comment:2 by Mariusz Felisiak, 7 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 by Mariusz Felisiak, 7 years ago

Has patch: set

comment:4 by Tim Graham, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by GitHub <noreply@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 99df304:

Fixed #28206 -- Fixed RawQuerySet crash on a model with a mixed case db_column pk on Oracle.

Thanks Tim Graham for the review.

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