Inconsistent column names in cursor.description under SQLite break RawQuerySet
|Reported by:||alex@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
See pull request at https://github.com/django/django/pull/2069
SQLite will sometimes return column names in cursor.description in the form table_alias."column_name" or simply "column_name" instead of just column_name. This can happen when returning columns from subqueries, views or unions.
This means that RawQuerySet can't match up the columns when trying to create model instances, and raises InvalidQuery: Raw query must include the primary key.
This change introduces a column_name_converter() to the backend introspection code to mirror table_name_converter() and implements the fix on the SQLite backend.
Change History (8)
comment:1 Changed 4 months ago by claudep
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:7 Changed 4 weeks ago by aaugustin
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Bug to Cleanup/optimization