From a4f691678fd042d83b44fc35b2c70aee3c237d87 Mon Sep 17 00:00:00 2001 From: Dias <110160920+diasdauletov@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:35:06 +0100 Subject: [PATCH] Throw an error for non-string `vars`. (#1461) --- core/session.ts | 6 ++++++ tests/core/core.spec.ts | 29 +++++++++++++++++++++++++++++ version.bzl | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/session.ts b/core/session.ts index f8058bef2..2ee0c54d3 100644 --- a/core/session.ts +++ b/core/session.ts @@ -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, diff --git a/tests/core/core.spec.ts b/tests/core/core.spec.ts index a83adef7b..9254475a3 100644 --- a/tests/core/core.spec.ts +++ b/tests/core/core.spec.ts @@ -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", () => { diff --git a/version.bzl b/version.bzl index dce7def9c..700fa7532 100644 --- a/version.bzl +++ b/version.bzl @@ -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"