Repository navigation
Conversation
rx.asset builds its URL with get_config(). Called at the top level of rxconfig.py, that started a second config load, which imported rxconfig.py again and recursed until RecursionError. While rxconfig.py is importing, _get_config() now returns the env and default config instead of importing it again, and get_config() does not cache that stand-in on the context. Signed-off-by: vjymisal0 <misalvijay153@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryStops config reads in
Previous review follow-up:
Reviews (21) · Last reviewed commit: "Merge main into fix/asset-in-rxconfig-re..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
…nd-in Constructing the stand-in Config published its default state_auto_setters, replacing the value a Config created earlier in rxconfig.py had set. State classes defined later lost their generated setters. Restore the published value after building the stand-in. Signed-off-by: vjymisal0 <misalvijay153@gmail.com>
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
… fails The mid-import stand-in Config publishes its state_auto_setters before validation, so a ConfigError (e.g. redis mode without a redis URL) left that value in place. Restore the saved value in a finally block. Signed-off-by: vjymisal0 <misalvijay153@gmail.com>
The env/default stand-in returned while rxconfig.py imports gave wrong values. rx.asset below `config = rx.Config(frontend_path=...)` lost the frontend path, so `reflex export` baked an asset URL that 404s. Modules that rxconfig.py imports, which read the real config on main, got the stand-in too: no custom attributes, no plugins, no db_url. A config read during the rxconfig.py import now: - returns the `config` that rxconfig.py already assigned; - raises ConfigError when rxconfig.py's own top-level code reads before it assigns `config`, because every nested import would run that read again and recurse forever; - else imports rxconfig.py once more, nested, as on main. A module that rxconfig.py imports does not run again, so the nested import ends. No Config is built mid-import, so the state_auto_setters save/restore and the get_config() no-cache branch go away.
Comments Outside DiffThese findings could not be posted inline.
|
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
A read after `config = rx.Config(...)` returns the half-imported module's config, and get_config() cached it on the context. When rxconfig.py then raised, the context kept that config, and the next get_config() returned it instead of loading the file again. Cache only after the outer import succeeds.
|
moving off deck, implementation is fairly complex for fixing what amounts to an edge case in a config architecture we're planning to eventually replace. |
|
Thanks for taking a look, @masenf, and for the context on the config architecture. That makes sense. Feel free to close this if it isn't useful with the planned replacement; I'm happy to help with that work instead if there's an issue to pick up. |
|
I investigated the CodSpeed report for This focused comparison runs both trees on one Linux runner, in base/head/head/base order, using Python 3.14.7, the same frozen dependencies, CodSpeed runner 5.6.3, and For This focused run did not reproduce the full suite's reported 5.14% regression. The full benchmark context may matter, so the cause remains unconfirmed. Could a maintainer rerun the Run benchmarks job for |
Summary
Calling
rx.asset(...)at the top level ofrxconfig.pyraisesRecursionError.AssetPathStr.__new__callsget_config()to prependfrontend_path. During the first config load, the context has no config yet, soget_config()calls_get_config(). That popsrxconfigfromsys.modulesand imports it again (_load_config_lockis anRLock, so the same thread re-enters). The re-import callsrx.assetagain, and the loop continues until the stack overflows.A config read from a module that
rxconfig.pyimports does not loop. The nested import does not run that module again, so the nested import ends and returns the real config. Only a read fromrxconfig.py's own top-level code runs again in every nested import.Changes:
_get_config()counts nestedrxconfig.pyimports in_config_import_depth, under_load_config_lock. A config read during the import:returns the
configthatrxconfig.pyalready assigned, if it did;raises
ConfigErrorifrxconfig.py's own top-level code reads before it assignsconfig(_rxconfig_body_is_reading()checks the innermost module-level frame). The message says to move the call below the assignment or into the app module;else imports
rxconfig.pyonce more, nested, as onmain. Reads from imported modules keep the real config.get_config()does not cache a config read whilerxconfig.pyimports. It caches only after the outer import succeeds, so arxconfig.pythat fails after a read is not hidden by a cached config.No
Configis built mid-import, so nothing has to restorestate_auto_setters.Behavior with
frontend_path="/sub"inrx.Config:|
rxconfig.py|main| This PR ||---|---|---|
|
rx.asset(...)belowconfig = rx.Config(...)|RecursionError|/sub/favicon.ico?v=…||
rx.asset(...)aboveconfig = rx.Config(...)(the issue's code) |RecursionError|ConfigErrorthat names the fix || A module imported above
config = ...reads the config or callsrx.asset| real config | real config (unchanged) |Above the assignment no config exists yet, so no value is correct there. An env/default stand-in would silently drop a
frontend_path, plugins or custom attributes set inrx.Config(...).Verification
Updated with actual
main(cb9ee91c) inb9008977. All three original PR file blobs are unchanged; the diff retains the config fix, its regressions, and the news fragment.reflex tests: zero errors, two existing unused-expression warnings.Historical evidence on the preceding
ee7355b7head: all reported upstream checks completed with 165 successes and three skips; the coverage job reported 83.21% against the required 72%. Its exact-URL and complete-error regression controls also passed. These earlier matrix and coverage results are not claimed for the new merge head; fresh upstream checks must finish there.This update does not claim a full native unit or integration run. No components changed, so no component stub/hash change is needed.
Closes #7669