Skip to content

fix: restore outer RefFactory after nested JSON deserialization - #443

Merged
zantvoort merged 1 commit into
mainfrom
fix/json-ref-factory-reentrancy
Aug 10, 2026
Merged

fix: restore outer RefFactory after nested JSON deserialization#443
zantvoort merged 1 commit into
mainfrom
fix/json-ref-factory-reentrancy

Conversation

@zantvoort

Copy link
Copy Markdown
Collaborator

The JSON converters in storm-jackson2, storm-jackson3, and storm-kotlinx-serialization bound the deserialization RefFactory with set and finally remove. A nested fromDatabase call, reachable through a custom deserializer that issues a query, removed the outer factory on its way out. The outer record's remaining Ref fields then saw no factory and fell back to detached refs, with no exception or log.

Each converter now saves the previous ThreadLocal value before binding and restores it on exit, removing the entry only when there was no previous value. This is the same save-and-restore discipline TransactionScope uses in core.

Each module gains a regression test in which a payload's first field carries a custom deserializer that runs a nested query (mapping Owner, whose @Json address field re-enters fromDatabase), followed by a Ref field. The test asserts the ref is attached and fetches. All three tests fail against the previous code with isFetchable() returning false.

Note on the kotlinx test: a @Contextual Ref<T> property inside a @Serializable class requires T itself to be @Serializable, since the compiler plugin resolves type-argument serializers even for contextual properties. The test therefore uses a @Serializable entity mapped to the owner table as the ref target.

Fixes #385

@zantvoort
zantvoort merged commit 13f4244 into main Aug 10, 2026
7 checks passed
@zantvoort
zantvoort deleted the fix/json-ref-factory-reentrancy branch August 10, 2026 22:00
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON converters: the RefFactory ThreadLocal is not reentrant, nested deserialization produces detached refs

1 participant