Repository navigation
Fix stale-requests cron by deferring auth setup to full app mode - #125
guillermodotn wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #125 +/- ##
==========================================
+ Coverage 83.84% 84.19% +0.35%
==========================================
Files 13 13
Lines 1374 1405 +31
==========================================
+ Hits 1152 1183 +31
Misses 222 222
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
lubomir
left a comment
There was a problem hiding this comment.
The main problem with the original code base is that it relies on global variables that are initialized at module import time. This makes it difficult to test and customize things where needed. The PR changes adds functions for the initializations, but keeps the global state. It needs to add complexity to ensure the state is read correctly. Architecturally, this doesn't seem better than prior state.
I'm wondering it would be easier to do a phased approach here. First convert the codebase to follow Flask best practices (current_app and app.config), and then fix the problem if still present.
| if "cts.views" in sys.modules: | ||
| import cts.views | ||
|
|
||
| cts.views.conf = conf |
There was a problem hiding this comment.
This seems rather fragile. If another module starts importing the config, it needs to be added here or confusing failures happen.
| from cts import create_app, db, models | ||
|
|
||
| # Bootstrap configuration for CLI option defaults without web auth/views. | ||
| create_app(mode="minimal") |
There was a problem hiding this comment.
With this import at top level, some of the handlers could create the application twice. Would it be cleaner to only create the app in the handlers?
| if "cts.views" in sys.modules: | ||
| import cts.views | ||
|
|
||
| cts.views.conf = self._saved_conf |
There was a problem hiding this comment.
This is effectively the same thing as _sync_conf_binding.
|
Close in favor of deeper refactor |
The stale-requests CronJob was failing at startup because LDAP bind validation ran for every
cts-managerinvocation, even though that job only needs database access.This introduces a Flask application factory with two modes:
LDAP configuration is now validated only when LDAP is actually queried, not at process startup.