Skip to content

CharField(blank=True) treated as nullable #736

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

Closed
zach-waggoner opened this issue Oct 20, 2021 · 2 comments
Closed

CharField(blank=True) treated as nullable #736

zach-waggoner opened this issue Oct 20, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@zach-waggoner
Copy link
Contributor

zach-waggoner commented Oct 20, 2021

What's wrong

When I run mypy with this plugin enabled, it infers the type for CharFields with blank=True as Optional[str].

How is that should be

I believe this is incorrect, as blank=True only permits empty strings, not NULL. It seems like this was allegedly fixed in #39, but I'm still having the same issue. I noticed that if I remove the following lines from DjangoContext.get_field_nullability, it works:

if not nullable and isinstance(field, CharField) and field.blank:
    return True

System information

  • OS:
  • python version: 3.9.7
  • django version: 3.2.9
  • mypy version: 0.910
  • django-stubs version: 1.9.0
  • django-stubs-ext version: N/A
@zach-waggoner zach-waggoner added the bug Something isn't working label Oct 20, 2021
@sobolevn
Copy link
Member

@zach-waggoner PR is welcome!

@flaeppe
Copy link
Member

flaeppe commented Sep 23, 2023

I cannot reproduce this, feel free to reopen with a breaking case.

@flaeppe flaeppe closed this as completed Sep 23, 2023
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

3 participants