fix(config): keep rxconfig dependencies on same-root reload

Merged
BE
3mo ago
+334-21

Summary

Fixes #7028

_get_config() evicts every project-local module that rxconfig.py imported before each load. rx.App() calls reload_config(), so every backend worker loads rxconfig.py twice and re-executes those modules in between. The app code imported before rx.App() keeps the first copies, sys.modules holds the second ones, and every class defined in an evicted module now exists twice.

For state-defining modules that is the StateValueError from #7028. For plain modules it is quieter and worse: pickle.dumps() of an instance of the app's copy fails with Can't pickle <class 'myapp.routes.Route'>: it's not the same object as myapp.routes.Route, because the qualified name resolves to the re-imported class. In our production app that made the auth substate unserializable, so it was never persisted to redis and clients got stuck on hydrate.

Changes

  • Record the project root the dependencies were captured under and only evict them when a load comes from a different root. A same-root load still re-reads rxconfig.py from disk; only its project-local imports are kept. This is option 1 from #7028.
  • Tests: same-root reload keeps the module object and pickling of a pre-reload instance works; a load from another project root still evicts and each project resolves its own same-named helper; the #7028 reproduction passes for both a plain reload_config() and a reload in a forked context (the AppHarness shape).

Testing

  • tests/units/test_config.py: 134 passed. The two same-root tests fail on main (one with the #7028 StateValueError).
  • ruff, pyright, codespell pass.