Call _get_was_touched through BaseState so a state var cannot shadow it

Merged
JO
3mo ago
+108-5

closes #7091

What

BaseStateToken.get_and_reset_touched_state (disk state manager), StateManagerRedis.set_state and the two SharedState update collectors call state._get_was_touched() on the instance. A state that defines a var with that name, e.g. _get_was_touched: int = 7, shadows the method on the instance, so every disk flush raised TypeError: 'int' object is not callable and the state was never persisted, while reads and writes from the browser kept working.

#7025 intentionally keeps such a name usable as a var (test_fast_path_skips_names_a_subclass_defines defines exactly this backend var), so instead of rejecting the name at class definition time, this calls the method through the class at the four internal call sites: BaseState._get_was_touched(state). User code that reads its own _get_was_touched var is unaffected.

Note: #6745 rewrites the redis.py line touched here, so whichever lands second will need the same one-line change.

Tests

Added test_base_state_token_get_and_reset_touched_shadowed_by_var to tests/units/istate/manager/test_token.py: a state with a _get_was_touched: int var and a modified base var is reported as touched, the flag is reset, and the var keeps its value. On current main it fails with TypeError: 'int' object is not callable at token.py:205; with this change it passes.

  • tests/units/istate and tests/units/test_state.py: 278 passed (277 on main plus the new test).
  • tests/units: 8365 passed. The 207 failures locally are all under tests/units/reflex_cli/v2/ and match what I see on main without this change; the pyi generator tests also error here only because ruff is not on PATH when pytest runs outside the activated venv, and pass with it.

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • Followed CONTRIBUTING.md; no other open PR for this change
  • Added a news fragment
  • ruff check, ruff format --check and pyright pass on the changed files