Skip to content

Fix Marshal serialization of Template, Environment, and ParseContext#2090

Open
SAY-5 wants to merge 1 commit into
Shopify:mainfrom
SAY-5:fix-marshal-environment
Open

Fix Marshal serialization of Template, Environment, and ParseContext#2090
SAY-5 wants to merge 1 commit into
Shopify:mainfrom
SAY-5:fix-marshal-environment

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 26, 2026

Templates can be compiled once and cached (as described in the wiki), but since 5.6.0 calling Marshal.dump on a compiled template raises TypeError: can't dump anonymous class because Environment holds an anonymous Class.new(StrainerTemplate) and ParseContext holds a StringScanner.

This PR adds marshal_dump/marshal_load to both Environment and ParseContext. Environment rebuilds its strainer template from the serialized filter module list on load; ParseContext excludes @string_scanner and creates a fresh one on load. The exception_renderer proc is not serializable and is restored to the default lambda on load.

Fixes #1913.

…rshal

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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.

Serializing a compiled Template using Marshal.dump fails after version 5.6.0

1 participant