Skip to content

Warn if INSTALLED_APPS['reactpy_django'] position looks suspicious #181

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Using the following categories, list your changes in this order:

## [Unreleased]

- Nothing (yet)!
### Added

- Warning W018 (`Suspicious position of 'reactpy_django' in INSTALLED_APPS`) has been added.

## [3.5.0] - 2023-08-26

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Follow the links below to find out more about this project.
- [Documentation](https://reactive-python.github.io/reactpy-django)
- [GitHub Discussions](https://github.com/reactive-python/reactpy-django/discussions)
- [Discord](https://discord.gg/uNb5P4hA9X)
- [Contributor Guide](https://reactive-python.github.io/reactpy-django/contribute/code/)
- [Contributor Guide](https://reactive-python.github.io/reactpy-django/latest/contribute/code/)
- [Code of Conduct](https://github.com/reactive-python/reactpy-django/blob/main/CODE_OF_CONDUCT.md)

<!--resources-end-->
24 changes: 19 additions & 5 deletions src/reactpy_django/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def reactpy_warnings(app_configs, **kwargs):
from reactpy_django.config import REACTPY_FAILED_COMPONENTS

warnings = []
INSTALLED_APPS: list[str] = getattr(settings, "INSTALLED_APPS", [])

# REACTPY_DATABASE is not an in-memory database.
if (
Expand Down Expand Up @@ -53,10 +54,7 @@ def reactpy_warnings(app_configs, **kwargs):
# Warn if REACTPY_BACKHAUL_THREAD is set to True with Daphne
if (
sys.argv[0].endswith("daphne")
or (
"runserver" in sys.argv
and "daphne" in getattr(settings, "INSTALLED_APPS", [])
)
or ("runserver" in sys.argv and "daphne" in INSTALLED_APPS)
) and getattr(settings, "REACTPY_BACKHAUL_THREAD", False):
warnings.append(
Warning(
Expand All @@ -72,7 +70,7 @@ def reactpy_warnings(app_configs, **kwargs):
warnings.append(
Warning(
"ReactPy client.js could not be found within Django static files!",
hint="Check your Django static file configuration.",
hint="Check all static files related Django settings and INSTALLED_APPS.",
id="reactpy_django.W004",
)
)
Expand Down Expand Up @@ -241,6 +239,22 @@ def reactpy_warnings(app_configs, **kwargs):
)
)

position_to_beat = 0
for app in INSTALLED_APPS:
if app.startswith("django.contrib."):
position_to_beat = INSTALLED_APPS.index(app)
if (
"reactpy_django" in INSTALLED_APPS
and INSTALLED_APPS.index("reactpy_django") < position_to_beat
):
warnings.append(
Warning(
"The position of 'reactpy_django' in INSTALLED_APPS is suspicious.",
hint="Move 'reactpy_django' below all 'django.contrib.*' apps, or suppress this warning.",
id="reactpy_django.W018",
)
)

return warnings


Expand Down