Skip to content

__year__in (transform + __in) regressed in 6.0.5: rejects list[int], expects Iterable[str | date] #3411

Description

@jgillard

Bug report

Disclaimer: I used AI to help debug this issue.

What's wrong

Updating from 6.0.3 to 6.0.5 led to this new error that is a false positive:

Incompatible type for lookup 'start_date__year__in': (got "list[int]", expected "Iterable[str | date]")

An example line is days_off.filter(start_date__year__in=years) where start_date is a DateField and years which is typed as list[int].

The transform is being ignored, and this seems to have come from #3314.

AI wrote this minimal repro:

from datetime import date
from django.db import models

class Event(models.Model):
    start_date = models.DateField()

def by_years(years: list[int]) -> models.QuerySet[Event]:
    return Event.objects.filter(start_date__year__in=years)   # ← false positive on 6.0.5

def by_year_scalar(year: int) -> models.QuerySet[Event]:
    return Event.objects.filter(start_date__year=year)        # control: OK

def by_date_in(dates: list[date]) -> models.QuerySet[Event]:
    return Event.objects.filter(start_date__in=dates)         # control: OK

How is that should be

This should not error.

System information

  • OS: MacOS 26.5
  • python version: 3.14.5
  • django version: 6.0.5
  • mypy version: 2.1.0
  • django-stubs version: 6.0.5
  • django-stubs-ext version: 6.0.5

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