Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def as_kwarg(key, value):
test_value = to_string(value)
is_function = re.match(r'^\s*(env_var|ref|var|source|doc)\s*\(.+\)\s*$',
test_value)
# if the value is a function, don't wrap it in quotes!
if is_function:
formatted_value = value
else:
formatted_value = value.__repr__()
return "{key}={value}".format(key=key, value=formatted_value)
def exception_handler(self, sql, model_name=None, connection_name=None):
try:
yield
except psycopg2.DatabaseError as e:
logger.debug('Postgres error: {}'.format(str(e)))
try:
# attempt to release the connection
self.release_connection(connection_name)
except psycopg2.Error:
logger.debug("Failed to release connection!")
pass
raise dbt.exceptions.DatabaseException(
dbt.compat.to_string(e).strip())
except Exception as e:
logger.debug("Error running SQL: %s", sql)
logger.debug("Rolling back transaction.")
self.release_connection(connection_name)
raise dbt.exceptions.RuntimeException(e)
def _safe_release_connection(self):
"""Try to release a connection. If an exception is hit, log and return
the error string.
"""
try:
self.adapter.release_connection()
except Exception as exc:
logger.debug(
'Error releasing connection for node {}: {!s}\n{}'
.format(self.node.name, exc, traceback.format_exc())
)
return dbt.compat.to_string(exc)
return None
def filter(self, record):
subbed = dbt.compat.to_string(record.msg)
for escape_sequence in dbt.ui.colors.COLORS.values():
subbed = subbed.replace(escape_sequence, '')
record.msg = subbed
return True
def as_kwarg(key, value):
test_value = to_string(value)
is_function = re.match(r'^\s*(ref|var)\s*\(.+\)\s*$', test_value)
# if the value is a function, don't wrap it in quotes!
if is_function:
formatted_value = value
else:
formatted_value = value.__repr__()
return "{key}={value}".format(key=key, value=formatted_value)
def _split_queries(cls, sql):
"Splits sql statements at semicolons into discrete queries"
sql_s = dbt.compat.to_string(sql)
sql_buf = StringIO(sql_s)
split_query = snowflake.connector.util_text.split_statements(sql_buf)
return [part[0] for part in split_query]
def _split_queries(cls, sql):
"Splits sql statements at semicolons into discrete queries"
sql_s = dbt.compat.to_string(sql)
sql_buf = StringIO(sql_s)
split_query = snowflake.connector.util_text.split_statements(sql_buf)
return [part[0] for part in split_query]
def get_hook_dict(hook, index):
if isinstance(hook, dict):
hook_dict = hook
else:
hook_dict = _parse_hook_to_dict(to_string(hook))
hook_dict['index'] = index
return hook_dict
connection_name='master'):
try:
yield
except google.cloud.exceptions.BadRequest as e:
message = "Bad request while running:\n{sql}"
self.handle_error(e, message, sql)
except google.cloud.exceptions.Forbidden as e:
message = "Access denied while running:\n{sql}"
self.handle_error(e, message, sql)
except Exception as e:
logger.debug("Unhandled error while running:\n{}".format(sql))
logger.debug(e)
raise dbt.exceptions.RuntimeException(dbt.compat.to_string(e))