Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Field.limit_choices_to with callable #2442

Open
H4rryK4ne opened this issue Nov 13, 2024 · 0 comments
Open

Error on Field.limit_choices_to with callable #2442

H4rryK4ne opened this issue Nov 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@H4rryK4ne
Copy link

Bug report

What's wrong

I get a mypy error when I use a callable on a ForeignKey.limit_choices_to argument:

error: Argument "limit_choices_to" to "ForeignKey" has incompatible type "Callable[[], dict[str, set[Any]]]"; expected "Q | dict[str, Any] | _ChoicesCallable | None"  [arg-type]

My code looks like this:

def limit_to_procedures() -> dict[str, set[Any]]:
    return {"pk__in": {content_type.pk for content_type in ContentType.objects.get_for_models(*AbstractModel.__subclasses__()).values()}} 

def Foo(Model):
  content_type = ForeignKey(ContentType, limit_choices_to=limit_to_procedures, on_delete=CASCADE)

How is that should be

No error should be thrown.

System information

  • OS: Linux
  • python version: 3.12.7
  • django version: 5.1.1
  • mypy version: 1.11.2
  • django-stubs version: 5.1.0
  • django-stubs-ext version: 5.1.0
@H4rryK4ne H4rryK4ne added the bug Something isn't working label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant