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

Acknowledge send_anonymous_usage_stats setting for python models #933

Merged
merged 9 commits into from
Mar 21, 2024
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240318-203635.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Acknowledge `send_anonymous_usage_stats` setting for python models
time: 2024-03-18T20:36:35.396323-04:00
custom:
Author: mikealfare
Issue: "830"
7 changes: 5 additions & 2 deletions dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ def submit_python_job(self, parsed_model: dict, compiled_code: str):
if imports:
imports = f"IMPORTS = ('{imports}')"

snowpark_telemetry_string = "dbtLabs_dbtPython"
snowpark_telemetry_snippet = f"""
if self.config.args.SEND_ANONYMOUS_USAGE_STATS:
snowpark_telemetry_string = "dbtLabs_dbtPython"
snowpark_telemetry_snippet = f"""
import sys
sys._xoptions['snowflake_partner_attribution'].append("{snowpark_telemetry_string}")"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why's the indenting all weird?

else:
snowpark_telemetry_snippet = ""

common_procedure_code = f"""
RETURNS STRING
Expand Down
43 changes: 43 additions & 0 deletions tests/functional/adapter/test_anonymous_usage_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dbt.tests.util import run_dbt_and_capture
import pytest


ANONYMOUS_USAGE_MESSAGE = """
sys._xoptions['snowflake_partner_attribution'].append("dbtLabs_dbtPython")
""".strip()


MY_PYTHON_MODEL = """
import pandas

def model(dbt, session):
dbt.config(materialized='table')
data = [[1,2]] * 10
return pandas.DataFrame(data, columns=['test', 'test2'])
"""


class AnonymousUsageStatsBase:
@pytest.fixture(scope="class")
def models(self):
return {"my_python_model.py": MY_PYTHON_MODEL}


class TestAnonymousUsageStatsOn(AnonymousUsageStatsBase):
@pytest.fixture(scope="class")
def project_config_update(self):
return {"flags": {"send_anonymous_usage_stats": True}}

def test_stats_get_sent(self, project):
_, logs = run_dbt_and_capture(["--debug", "run"])
assert ANONYMOUS_USAGE_MESSAGE in logs


class TestAnonymousUsageStatsOff(AnonymousUsageStatsBase):
@pytest.fixture(scope="class")
def project_config_update(self, dbt_profile_target):
return {"flags": {"send_anonymous_usage_stats": False}}

def test_stats_do_not_get_sent(self, project):
_, logs = run_dbt_and_capture(["--debug", "run"])
assert ANONYMOUS_USAGE_MESSAGE not in logs
Loading