You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deeply nested js_data still raises RecursionError while Citry copies it #393
Rendering raises RecursionError, with or without js. The data reaches PreparedOccurrence, which copies it in _detach_object (packages/py/citry/citry/_vue/prepared.py). Two steps there use one Python frame or more per level:
_validate_keys calls itself once for each nested dict or list.
The copy is json.loads(json.dumps(value, allow_nan=False)). On Python 3.11, both the C encoder and the C decoder count each level against the recursion limit, so the depth they reach is lower there. Later CPython versions stop both at a fixed limit of their own, however many frames are free: about 10,000 levels on 3.13, and between 20,000 and 100,000 on 3.14.
Why it matters
The JSON check that runs before this copy (_json_plain) now reaches any depth (#391), so it reports a Secret or a value that is not JSON wherever it sits. Plain deep data then fails one step later, in this copy. A deep <c-for> chain does not hit this path, because its data does not go through server_data.
Suggested fix
Validation: walk _validate_keys with a stack.
The copy: replace the json.dumps/json.loads round trip with a copy that uses a stack and reproduces the round trip exactly:
tuples become lists;
a str, int or float subclass becomes the exact type;
NaN and infinity raise the same ValueError, and a value that is not JSON raises the same TypeError;
a loop raises the same ValueError.
Tests: compare the new copy with the round trip on random data, and add a test that renders 2,000-level js_data with little stack left.
Speed: the round trip runs on every render whose js_data() is not empty, so the new copy needs a speed check against it.
Related
_canonical_json in ext/events/tokens.py has the same Python 3.11 recursion limit for a deeply nested State value, so fix it in the same change.
Activity
fix: copy deeply nested js_data() on any Python