Point to repr() for printed backend vars; skip the storage factory check at runtime

Merged
MA
17d ago
+96-6

Found in the reflex 0.11.0a1 pre-release testing (FINDING-037, FINDING-038).

These are two small client-vars fix-ups, one commit each. They touch separate files and can be split into two PRs if you prefer.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

FINDING-037: printing a class-level backend var in server code. Since #7651, Field.__str__ raises BackendVarFormatError. So print(State._secret), str(), "%s" % and logging of a class-level backend var or mixin field in server code raise too, and the message only talks about the UI. This change keeps the behaviour (it is intentional) and makes two additions:

  • Field._no_frontend_var_error now ends every variant of the message with "To print or log the field itself in server code, use repr()."
  • The unreleased #7651 fragment (packages/reflex-base/news/+backend-var-literal-var.bugfix.md) now says that print() and logging in server code are affected and to use repr() there.

FINDING-038: extra default_factory calls. The compile calls a str-compatible default_factory to reject one that produces browser storage (#7582). _shared_storage_groups reruns _compile_client_storage_recursive in each backend worker's first event (hydrate_and_load → _sync_shared_storage), so every such factory ran once more per worker. _compile_client_storage_field and _compile_client_storage_recursive now take a keyword check_factory / check_factories (default True), and the runtime path passes False. The compile still runs the check, so the one extra call per compile stays, as agreed.

Tests

  • tests/units/reflex_base/vars/test_base.py::test_field_format_error_suggests_repr (backend, mixin, state-var field and unbound field): str(field) raises a message that ends with the repr() hint, and repr(field) still works. It fails before the change.
  • tests/units/test_state.py::test_shared_storage_groups_do_not_call_default_factories: a counting factory on str and str | None vars is not called by _shared_storage_groups, and the shared-name groups are unchanged. Before the change, the factory was called twice.
  • uv run pytest tests/units --cov passes (81.4% coverage; tests/units/reflex_bench/drivers/test_browser.py was skipped because Chromium is not installed here). ruff check, ruff format and pyright reflex tests are clean.

Generated by Claude Code