django/django — pull request #2069 by AlexHill (2013-12-13 06:13:10+00:00)
Title: Fix fetching models from complex RawQuerySets in SQLite

SQLite will sometimes (returning columns from subqueries or views for example) return column names in the form ``table_alias."column_name"`` or simply ``"column_name"`` instead of just ``column_name``.

This meant 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.

This is the same behaviour accounted for in SQLAlchemy here: https://github.com/zzzeek/sqlalchemy/blob/4663ec98b226a7d495846f0d89c646110705bb30/lib/sqlalchemy/dialects/sqlite/base.py#L591