Skip to content
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

Python model logging #1115

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,15 @@ def submit_python_job(self, parsed_model: dict, compiled_code: str):
if use_anonymous_sproc:
proc_name = f"{identifier}__dbt_sp"
python_stored_procedure = f"""
ALTER SESSION SET TRACE_LEVEL = ON_EVENT;
WITH {proc_name} AS PROCEDURE ()
{common_procedure_code}
CALL {proc_name}();
"""
else:
proc_name = f"{database}.{schema}.{identifier}__dbt_sp"
python_stored_procedure = f"""
ALTER SESSION SET TRACE_LEVEL = ON_EVENT;
CREATE OR REPLACE PROCEDURE {proc_name} ()
{common_procedure_code};
CALL {proc_name}();
Expand Down
43 changes: 43 additions & 0 deletions tests/functional/adapter/python_model_tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dbt.tests.util import run_dbt
import pytest


MODEL__LOGGING = """
import logging

import snowflake.snowpark as snowpark
import snowflake.snowpark.functions as f
from snowflake.snowpark.functions import *


logger = logging.getLogger("dbt_logger")
logger.setLevel(logging.INFO)
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
logger.info("******Inside Logging module.******")


def model(dbt, session: snowpark.Session):
logger.info("******Logging start.******")
df=session.sql(f"select current_user() as session_user, current_role() as session_role")
logger.info("******Logging End.******")
return df
"""


class TestPythonModelLogging:
"""
This test case addresses bug report https://github.com/dbt-labs/dbt-snowflake/issues/846

-- before running:
USE ROLE ACCOUNTADMIN;
ALTER ACCOUNT UNSET LOG_LEVEL;
ALTER ACCOUNT UNSET TRACE_LEVEL;
GRANT MODIFY SESSION LOG LEVEL ON ACCOUNT TO ROLE <DBT_ROLE>;
GRANT MODIFY SESSION TRACE LEVEL ON ACCOUNT TO ROLE <DBT_ROLE>;
"""

@pytest.fixture(scope="class")
def models(self):
return {"logging_model.py": MODEL__LOGGING}

def test_logging(self, project):
run_dbt(["run"])
Loading