-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Use lazy imports to avoid Django side-effects
- Loading branch information
Showing
3 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class LazyDjango: | ||
""" | ||
Django has a few modules where if you import something from them, | ||
they trigger side-effects that can crash the app if called at import-time | ||
vs run-time. Notably things related to auth that trigger apps / settings | ||
checks. | ||
This class is a workaround, without using a full app registration system, | ||
to just use lazy-imports. | ||
""" | ||
|
||
@property | ||
def redirect_to_login(self): | ||
if self._redirect_to_login is None: | ||
from django.contrib.auth.views import redirect_to_login | ||
|
||
self._redirect_to_login = redirect_to_login | ||
return self._redirect_to_login | ||
|
||
|
||
lazy_django = LazyDjango() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters