Skip to content

fix: resolveSnippetRef ignores in-session cache, causing forward snippet references to fail #509

@ako

Description

@ako

Bug

When a CREATE PAGE precedes a CREATE SNIPPET in the same script, the snippet reference fails even though both are in the script. The reverse order (snippet first, then page) works.

Root cause

resolveSnippetRef in mdl/executor/cmd_pages_builder_input.go queries the backend directly and never checks ctx.Cache.createdSnippets. By contrast, resolveMicroflow and resolvePageRef both check the in-session cache first, so forward references to microflows and pages within the same script work correctly.

The fix is a single cache lookup in resolveSnippetRef before falling through to the backend query — identical to the pattern already used in the other two resolver functions.

Reproduction

-- This order fails: page references snippet not yet in the DB
create page MyModule.Overview (...) {
  snippetcall MyModule.Header;
};

create snippet MyModule.Header (...) { ... }
-- This order succeeds
create snippet MyModule.Header (...) { ... }
create page MyModule.Overview (...) {
  snippetcall MyModule.Header;
};

Affected files

  • mdl/executor/cmd_pages_builder_input.goresolveSnippetRef function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions