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

Improve system check registry hints #1249

Merged
merged 7 commits into from
Jan 8, 2023

Conversation

intgr
Copy link
Collaborator

@intgr intgr commented Nov 11, 2022

The @register decorator from django.core.checks was previously untyped.

Fixes #1098.

@intgr intgr force-pushed the check-registry-hints branch from a4a1974 to a6334c5 Compare December 13, 2022 14:51
@intgr intgr requested a review from adamchainz December 13, 2022 14:52
@intgr
Copy link
Collaborator Author

intgr commented Dec 13, 2022

@sobolevn Any ideas why only "pre-commit.ci" checks are running, but not the remaining workflows?

@sobolevn
Copy link
Member

No :(

@intgr
Copy link
Collaborator Author

intgr commented Dec 13, 2022

After making a new push, the workflows are now running. I guess it was a temporary GitHub glitch.

@intgr intgr force-pushed the check-registry-hints branch from a86eef1 to e31c9c7 Compare December 13, 2022 17:59
@intgr
Copy link
Collaborator Author

intgr commented Dec 15, 2022

This should be ready for review. @adamchainz do you have time to look at this again?

@intgr
Copy link
Collaborator Author

intgr commented Jan 4, 2023

Ping, this has been waiting for 3 weeks. @adamchainz @sobolevn?

Copy link
Contributor

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes - writing and pushing a fix.

_CheckCallable: TypeAlias = Callable[..., Sequence[CheckMessage]]
class _CheckCallable(Protocol):
def __call__(
self, *, app_configs: Apps, databases: Sequence[str] | None, **kwargs: Any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app_configs has the wrong type - it's a list of AppConfig, or None.

See https://docs.djangoproject.com/en/4.1/topics/checks/#writing-your-own-checks

The check function must accept an app_configs argument; this argument is the list of applications that should be inspected. If None, the check must be run on all installed apps in the project.

And an example check function in one of my packages: https://github.com/adamchainz/django-linear-migrations/blob/main/src/django_linear_migrations/apps.py#L129

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh that was sloppy. Thanks for the fixes!

Comment on lines 9 to 13
@register("foo", deploy=True)
def check_foo(app_configs: Apps, databases: Optional[Sequence[str]], **kwargs: Any) -> list[Warning]:
if databases and 'databass' in databases:
return [Warning("Naughty list")]
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most checks don't take a databases argument, so I'd like a test that checks that situation too

@adamchainz
Copy link
Contributor

Tests failing until #1313...

@sobolevn sobolevn closed this Jan 7, 2023
@sobolevn sobolevn reopened this Jan 7, 2023
Copy link
Contributor

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to go, but I'm not going to merge as I was the last to touch it.

@sobolevn
Copy link
Member

sobolevn commented Jan 8, 2023

Thanks everyone!

@sobolevn sobolevn merged commit 8ade002 into typeddjango:master Jan 8, 2023
@jaap3
Copy link

jaap3 commented Jan 8, 2023

Lovely stuff, thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Using the django.core.checks.register makes function untyped
4 participants