Skip to content

Using fields parameter or method without flatten=True does not seem to work on values and values_list #800

@pawamoy

Description

@pawamoy

Describe the bug
I'm trying to get a single field from a filtered set of rows.

I've tried the following:

branches = await ProjectDependency.objects.filter(project__id=project_id).values_list(fields=["git_branch"])
branches = await ProjectDependency.objects.filter(project__id=project_id).fields("git_branch").values_list()

But they both return other columns as well as git_branch:

[
  [
    "develop",
    1,
    "project name A",
    "project code A",
    1,
    "platform A"
  ],
  [
    "",
    1,
    "project name B",
    "project code B",
    1,
    "platform B"
  ]
]

If I add flatten=True, it works correctly:

branches = await ProjectDependency.objects.filter(project__id=project_id).values_list(fields=["git_branch"], flatten=True)
[
  "",
  "develop"
]

Is this intentional? Maybe I'm missing something.
I would expect the version without flatter to return this:

[
  [""],
  ["develop"]
]

Versions (please complete the following information):

  • Database backend used: sqlite
  • Python version: 3.8
  • ormar version: 0.11.2
  • pydantic version: 1.9.1
  • if applicable fastapi version: 0.79.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions