Skip to content

Commit

Permalink
Throw an error for non-string vars. (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
diasdauletov committed Feb 16, 2023
1 parent 32f68df commit a4f6916
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ export class Session {
"dataform.json"
);
}
if (
!!this.config.vars &&
!Object.values(this.config.vars).every((value) => typeof value === 'string')
) {
throw new Error("Custom variables defined in dataform.json can only be strings.");
}

const compiledGraph = dataform.CompiledGraph.create({
projectConfig: this.config,
Expand Down
29 changes: 29 additions & 0 deletions tests/core/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,35 @@ suite("@dataform/core", () => {
"A defaultLocation is required for BigQuery. This can be configured in dataform.json.",
]);
});

test("variables defined in dataform.json must be strings", () => {
const sessionFail = new Session(path.dirname(__filename), {
warehouse: "bigquery",
defaultSchema: "schema",
defaultLocation: "location",
vars: {
int_var: 1,
str_var: "str"
}
} as any);

expect(() => {
sessionFail.compile();
}).to.throw("Custom variables defined in dataform.json can only be strings.");

const sessionSuccess = new Session(path.dirname(__filename), {
warehouse: "bigquery",
defaultSchema: "schema",
defaultLocation: "location",
vars: {
str_var1: "str1",
str_var2: "str2"
}
} as any);

const graph = sessionSuccess.compile();
expect(graph.graphErrors.compilationErrors).to.eql([]);
});
});

suite("compilers", () => {
Expand Down
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NOTE: If you change the format of this line, you must change the bash command
# in /scripts/publish to extract the version string correctly.
DF_VERSION = "2.4.1"
DF_VERSION = "2.4.2"

0 comments on commit a4f6916

Please sign in to comment.