fix(config): load rxconfig with cwd prepended - #6933
Conversation
… sys.path, racing concurrent first-time imports
_load_config cleared sys.path down to the cwd for the duration of the
rxconfig import, so any concurrent first-time import in another thread
failed with ModuleNotFoundError (e.g. the lazy granian import when the
backend starts while another thread loads the config). Prepending the cwd
keeps the same resolution priority without blinding other threads.
Dropping the clear also removes the except-retry fallback, which had been
papering over a second bug: find_spec("rxconfig") answers from sys.modules,
so a leftover module from another project directory faked the existence
probe. Evict rxconfig from sys.modules before probing instead.
Greptile SummaryThe PR changes configuration loading to preserve the process import path during rxconfig imports and introduces thread-scoped tracking for project-local dependencies.
Confidence Score: 4/5The PR is not yet safe to merge because project configuration code can remove the temporary meta-path recorder and turn configuration loading into a cleanup failure. The unconditional recorder removal can raise ValueError after arbitrary rxconfig execution, masking the original import result and preventing the intended failed-import dependency cleanup. Files Needing Attention: packages/reflex-base/src/reflex_base/config.py
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/config.py | Preserves sys.path during configuration imports and narrows dependency tracking, but meta-path cleanup can raise if project code mutates the installed recorder. |
| tests/units/test_config.py | Adds regression coverage for concurrent imports, caller-owned path entries, and dependency attribution. |
| packages/reflex-base/news/6933.bugfix.md | Documents the configuration-loading concurrency and stale-module fixes. |
Reviews (4): Last reviewed commit: "Merge branch 'main' into fix-config-sysp..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…y the inserted cwd entry
abulvenz
left a comment
There was a problem hiding this comment.
Thanks, nice finding. I would improve on the in-code-comment as annotated. In the tests those comments can help to understand why that test is needed.
| sys.path here made concurrent first-time imports elsewhere fail with | ||
| ModuleNotFoundError for the duration of the rxconfig import. |
There was a problem hiding this comment.
This comment describes the historic version that is now gone.
| try: | ||
| rxconfig = importlib.import_module(constants.Config.MODULE) | ||
| finally: | ||
| sys.meta_path.remove(recorder) |
There was a problem hiding this comment.
Meta-path cleanup masks load result
When rxconfig.py or one of its imports removes or rebuilds sys.meta_path, this unconditional removal raises ValueError, turning a successful configuration load into a failure or masking the original import exception and skipping dependency recording.
| sys.meta_path.remove(recorder) | |
| for i, finder in enumerate(sys.meta_path): | |
| if finder is recorder: | |
| del sys.meta_path[i] | |
| break |
Uh oh!
There was an error while loading. Please reload this page.