Skip to content

ManyToMany relation wrongly validates values_list field name #2284

@Andrioden

Description

@Andrioden

Bug report

The following code gives error when it should not

class Cube(Model):
    heat = IntegerField(default=0)


class Ice(Model):
    cubes = ManyToManyField(Cube, blank=True)

    def heat_sum(self) -> int:
        return sum(self.cubes.values_list("heat", flat=True)) # <-- Error

What's wrong

mypy gives error

error: Cannot resolve keyword 'heat' into field. Choices are: cube, cube_id, ice, ice_id, id [misc]

How is that should be

No error

System information

  • OS: windows
  • python version: 3.12.1
  • django version: 5.0.3
  • mypy version: 1.11.0
  • django-stubs version: 5.0.3
  • django-stubs-ext version: 5.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions