-
Notifications
You must be signed in to change notification settings - Fork 199
Prevent .sqlx files in actions.yaml configs with a clear error #2189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aicayzer
wants to merge
1
commit into
dataform-co:main
Choose a base branch
from
aicayzer:feat/validate-actions-yaml-sqlx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+176
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,51 @@ export function main(coreExecutionRequest: Uint8Array | string): Uint8Array | st | |
| return dataform.CoreExecutionResponse.encode(coreExecutionResponse).finish(); | ||
| } | ||
|
|
||
| // Every action type that accepts a `filename` in actions.yaml. Referencing a | ||
| // .sqlx file (including a data-preparation .dp.sqlx file) is unsupported: .sqlx | ||
| // files are compiled directly from the definitions/ directory by the sqlx | ||
| // compiler, not through the `actions.yaml` config. Without this check a .sqlx | ||
| // filename produces a cryptic `nativeRequire` error rather than a useful | ||
| // diagnostic, so we emit a clear compilation error up front. See issue #1785. | ||
| const ACTION_TYPES_REJECTING_SQLX_FILENAMES: string[] = [ | ||
| "table", | ||
| "view", | ||
| "incrementalTable", | ||
| "assertion", | ||
| "operation", | ||
| "declaration", | ||
| "notebook", | ||
| "dataPreparation" | ||
| ]; | ||
|
|
||
| function actionConfigFilenameIsInvalidSqlx( | ||
| session: Session, | ||
| actionConfig: dataform.ActionConfig, | ||
| actionConfigsPath: string | ||
| ): boolean { | ||
| for (const actionType of ACTION_TYPES_REJECTING_SQLX_FILENAMES) { | ||
| const subConfig = (actionConfig as any)[actionType] as | ||
| | { filename?: string } | ||
| | undefined | ||
| | null; | ||
|
Comment on lines
+101
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: don't use dynamic casts to |
||
| const filename = subConfig?.filename; | ||
| if (filename && filename.toLowerCase().endsWith(".sqlx")) { | ||
| session.compileError( | ||
| new Error( | ||
| `Action config "${actionType}" has filename "${filename}", but .sqlx ` + | ||
| `files cannot be referenced from actions.yaml. .sqlx files are ` + | ||
| `compiled directly from the definitions/ directory. Either use a ` + | ||
| `.sql file with the same contents, or remove the actions.yaml ` + | ||
| `entry and let Dataform pick up the .sqlx file automatically.` | ||
| ), | ||
| actionConfigsPath | ||
| ); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| function loadActionConfigs(session: Session, filePaths: string[]) { | ||
| filePaths | ||
| .filter( | ||
|
|
@@ -89,6 +134,10 @@ function loadActionConfigs(session: Session, filePaths: string[]) { | |
| actionConfigs.actions.forEach(nonProtoActionConfig => { | ||
| const actionConfig = dataform.ActionConfig.create(nonProtoActionConfig); | ||
|
|
||
| if (actionConfigFilenameIsInvalidSqlx(session, actionConfig, actionConfigsPath)) { | ||
| return; | ||
| } | ||
|
|
||
| if (actionConfig.table) { | ||
| session.actions.push( | ||
| new Table( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actionConfigIncludesSqlxFiles?