Opened 5 years ago

Closed 5 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


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 5 years ago.

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by Mariusz Felisiak

Attachment: 28206.diff added


comment:1 Changed 5 years ago by Mariusz Felisiak

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

comment:2 Changed 5 years ago by Mariusz Felisiak

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 Changed 5 years ago by Mariusz Felisiak

Has patch: set

comment:4 Changed 5 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

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

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