Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_var_defined_is_missing(self):
var = Var(self.model, self.context, overrides={})
var.assert_var_defined('foo', 'bar')
with self.assertRaises(dbt.exceptions.CompilationException):
var.assert_var_defined('foo', None)
def _load_schema_tests(self):
parser = SchemaParser(self.root_project, self.all_projects,
self.macro_manifest)
for project_name, project in self.all_projects.items():
tests, patches = parser.load_and_parse(
package_name=project_name,
root_dir=project.project_root,
relative_dirs=project.source_paths
)
for unique_id, test in tests.items():
if unique_id in self.tests:
dbt.exceptions.raise_duplicate_resource_name(
test, self.tests[unique_id],
)
self.tests[unique_id] = test
for name, patch in patches.items():
if name in self.patches:
dbt.exceptions.raise_duplicate_patch_name(
name, patch, self.patches[name]
)
self.patches[name] = patch
def _expect_match(self, expected_name, *patterns, **kwargs):
match = self._first_match(*patterns, **kwargs)
if match is None:
msg = 'unexpected EOF, expected {}, got "{}"'.format(
expected_name, self.data[self.pos:]
)
dbt.exceptions.raise_compiler_error(msg)
return match
def process_currently_compiling(self, *args, **kwargs):
raise dbt_error(dbt.exceptions.RPCCompiling('compile in progress'))
def get_hooks_from_project(cls, config, hook_type):
if hook_type == RunHookType.Start:
hooks = config.on_run_start
elif hook_type == RunHookType.End:
hooks = config.on_run_end
else:
dbt.exceptions.InternalException(
'hook_type must be one of "{}" or "{}"'
.format(RunHookType.Start, RunHookType.End))
if type(hooks) not in (list, tuple):
hooks = [hooks]
return hooks
continue
connection, cursor = super().add_query(
individual_query, auto_begin,
bindings=bindings,
abridge_sql_log=abridge_sql_log
)
if cursor is None:
conn = self.get_thread_connection()
if conn is None or conn.name is None:
conn_name = ''
else:
conn_name = conn.name
raise dbt.exceptions.RuntimeException(
"Tried to run an empty query on model '{}'. If you are "
"conditionally running\nsql, eg. in a model hook, make "
"sure your `else` clause contains valid sql!\n\n"
"Provided SQL:\n{}"
.format(conn_name, sql)
)
return connection, cursor
def warn_invalid(filepath, key, value, explain):
msg = (
"Invalid test config given in {} @ {}: {} {}"
).format(filepath, key, value, explain)
dbt.exceptions.warn_or_error(msg, value,
log_fmt='Compilation warning: {}\n')
if len(args) == 1:
name = args[0]
elif len(args) == 2:
package, name = args
else:
dbt.exceptions.ref_invalid_args(self.model, args)
target_model = ParserUtils.resolve_ref(
self.manifest,
name,
package,
self.current_project,
self.model.package_name)
if target_model is None or target_model is ParserUtils.DISABLED:
dbt.exceptions.ref_target_not_found(
self.model,
name,
package)
return target_model, name
def _rollback(cls, connection):
"""Roll back the given connection.
"""
if dbt.flags.STRICT_MODE:
assert isinstance(connection, Connection)
if connection.transaction_open is False:
raise dbt.exceptions.InternalException(
'Tried to rollback transaction on connection "{}", but '
'it does not have one open!'.format(connection.name))
logger.debug('On {}: ROLLBACK'.format(connection.name))
cls._rollback_handle(connection)
connection.transaction_open = False
return connection