.values_list on a QuerySet enforces the use of Model attribute names, but does not account for db_field attribute/field name mappings

Description

Building a query set from a Model we run into problems if we want to use .values_list to avoid creating objects on the results with a model that has a db_field defined.

An example model:

Then later we wish to query this but get back the results efficiently:

This throws an exception like the following, and changing to the original table field name doesn't work out because it's hard dependent on the attribute present in the Model:

Environment

None

Activity

Show:
Jaume Marhuenda
July 6, 2017, 4:49 AM

Thanks for the report, this looks like a bug. It seems internally in some places of the code the correct mapping between db_field and the columns name is not done properly. I've pushed a potential solution and added the script as a test.

Fixed

Assignee

Unassigned

Reporter

Matt Oates

Fix versions

Labels

Reproduced in

None

PM Priority

None

External issue ID

None

Doc Impact

None

Reviewer

None

Size

None

Pull Request

None

Affects versions

Priority

Major