Skip to content

Conversation

@tomfrew
Copy link

@tomfrew tomfrew commented Jan 8, 2026

Summary

Fixes a crash in PythonParser.ts when parsing YAML values that get interpreted as f-strings with single-letter content.

When the YAML schema compiler processes string values, it wraps them as f"..." for interpolation support. However, single letters like F become f"F" which causes the Python parser to crash with "Cannot read properties of undefined (reading 'type')" because the parser doesn't handle empty children arrays.

The Bug

In YamlCompiler.ts, all YAML string values get wrapped as f-strings:

value = \`f"\${value}"\`;

When the value is just F, it becomes f"F" which the String_templateContext handler tries to process but children array is empty, causing:

children[children.length - 1].type  // crashes when children.length === 0

The Fix

Added an early return in PythonParser.ts to handle the empty children case:

if (children.length === 0) {
  const text = node.getText();
  const match = text.match(/^[fF]["'](.*)["']$/s);
  const content = match ? match[1] : text;
  return t.templateLiteral(
    [t.templateElement({ raw: content, cooked: content }, true)],
    []
  );
}

Reproducer

This YAML schema causes the crash:

cubes:
  - name: Products
    sql: SELECT * FROM products
    dimensions:
      - name: status
        sql: status
        type: string
        meta:
          enumValues:
            - A
            - B
            - F  # This single letter causes the crash

Test

Added a test case in yaml-schema.test.ts to prevent regression.

Checklist

  • Unit test added
  • No breaking changes

@tomfrew tomfrew requested a review from a team as a code owner January 8, 2026 15:58
@github-actions github-actions bot added javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members. labels Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant