Skip to content

Prevent .sqlx files in actions.yaml configs with a clear error#2189

Open
aicayzer wants to merge 1 commit into
dataform-co:mainfrom
aicayzer:feat/validate-actions-yaml-sqlx
Open

Prevent .sqlx files in actions.yaml configs with a clear error#2189
aicayzer wants to merge 1 commit into
dataform-co:mainfrom
aicayzer:feat/validate-actions-yaml-sqlx

Conversation

@aicayzer
Copy link
Copy Markdown

Closes #1785.

Problem

Referencing a .sqlx file from definitions/actions.yaml (e.g.

actions:
- table:
    filename: my_table.sqlx

) is unsupported, but the existing code path doesn't say so. The Table/View/etc. constructor reaches nativeRequire(config.filename).query, which fails with a Cannot find module 'definitions/my_table.sqlx' (or equivalently obscure) error far from the actual mistake. As Ekrekr noted on the issue, "this results in strange compilation behavior, and can cause cryptic errors."

Fix

Validate filenames at the loadActionConfigs entry point, before the action is constructed. For each action config sub-message that exposes a filename field — table, view, incrementalTable, assertion, operation, declaration, notebook — if filename ends in .sqlx (case-insensitive), emit a session.compileError naming the action type, the offending filename, and the remediation (use .sql, or rely on Dataform's automatic .sqlx discovery). The action is then skipped so a downstream nativeRequire error doesn't fire on top.

dataPreparation is intentionally excluded: it supports .dp.sqlx files via its own loader (core/actions/data_preparation.ts).

Test plan

Added one new test suite to core/main_test.ts (".sqlx filenames in actions.yaml are rejected with a clear error") covering:

  • One test per affected action type (7 in total), each verifying that a single compilation error fires with the expected message shape.
  • One case-insensitive test (filename: table.SQLX).
  • One regression test ensuring dataPreparation with a .dp.sqlx filename does not trigger this validation.

tslint --project . passes locally. I wasn't able to run bazel test //core/... locally (a @npm//@bazel/typescript:index.bzl loading error in tools/ts_library.bzl against bazel 5.4.0 on my machine), so the unit tests will be exercised by CI here.

Scope

No proto changes. No CLI wiring. No yargs wrapper edits. Scope mirrors PR #2154 (validation + clear error in core/, +16/-5).

Files touched

  • core/main.ts — new actionConfigFilenameIsInvalidSqlx helper called from loadActionConfigs.
  • core/main_test.ts — new test suite.

@aicayzer aicayzer requested a review from a team as a code owner May 29, 2026 20:58
@aicayzer aicayzer requested review from udim and removed request for a team May 29, 2026 20:58
@kolina
Copy link
Copy Markdown
Contributor

kolina commented Jun 4, 2026

/gcbrun

Comment thread core/main.ts
Comment on lines +103 to +106
const subConfig = (actionConfig as any)[actionType] as
| { filename?: string }
| undefined
| null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't use dynamic casts to any and and just statically list all unsupported types following this pattern

Comment thread core/main.ts
"notebook"
];

function actionConfigFilenameIsInvalidSqlx(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actionConfigIncludesSqlxFiles?

Copy link
Copy Markdown
Contributor

@kolina kolina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't notice tests are failing with YAML require failed run_core: VMError: Cannot find module './workflow_settings.yaml' before approving.

Can you please rebase on the latest HEAD? I think this error is not related to your changes and was fixed in the latest version

Putting a .sqlx file under the ``filename`` field of an entry in
``definitions/actions.yaml`` used to fall through to ``nativeRequire``,
which then failed with a cryptic error far from the source of the
mistake. ``actions.yaml`` is for plain ``.sql`` files; ``.sqlx`` files are
loaded directly from the ``definitions/`` directory by the sqlx compiler.

Add an explicit validation step in ``loadActionConfigs`` that runs before
each action is constructed. If the action's ``filename`` ends in
``.sqlx`` (case-insensitive), emit a ``compileError`` naming the action
type, the offending filename, and pointing at the fix. The action is
then skipped so we don't double-up with a downstream ``nativeRequire``
error.

The check covers ``table``, ``view``, ``incrementalTable``,
``assertion``, ``operation``, ``declaration`` and ``notebook``. Data
preparations are intentionally excluded because they support ``.dp.sqlx``
files via their own dedicated loader.

Closes dataform-co#1785
@aicayzer aicayzer force-pushed the feat/validate-actions-yaml-sqlx branch from 52f7337 to f604e1e Compare June 4, 2026 12:59
@aicayzer
Copy link
Copy Markdown
Author

aicayzer commented Jun 4, 2026

No problem at all @kolina, just rebased onto the latest main. Lmk if it's still something.

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.

Prevent putting .sqlx files in actions.yaml configs

2 participants