Skip to content

Commit

Permalink
fixed the issue in DO_NOT_TRACK code
Browse files Browse the repository at this point in the history
  • Loading branch information
iknox-fa committed Feb 8, 2023
1 parent cb05818 commit 74dde44
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 24 deletions.
10 changes: 3 additions & 7 deletions core/dbt/cli/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,9 @@ def assign_params(ctx, params_assigned_from_default):
object.__setattr__(self, "LOG_PATH", log_path)

# Support console DO NOT TRACK initiave
object.__setattr__(
self,
"ANONYMOUS_USAGE_STATS",
False
if os.getenv("DO_NOT_TRACK", "").lower() in ("1", "t", "true", "y", "yes")
else True,

This comment has been minimized.

Copy link
@iknox-fa

iknox-fa Feb 8, 2023

Author Contributor

else True
Yoicks, not sure how we missed that one.

)
if os.getenv("DO_NOT_TRACK", "").lower() in ("1", "t", "true", "y", "yes"):
object.__setattr__(self, "SEND_ANONYMOUS_USAGE_STATS", False)

# Check mutual exclusivity once all flags are set
self._assert_mutually_exclusive(
params_assigned_from_default, ["WARN_ERROR", "WARN_ERROR_OPTIONS"]
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def invoke(self, args: List[str]) -> Tuple[Optional[List], bool]:
epilog="Specify one of these sub-commands and you can find more help from there.",
)
@click.pass_context
@p.anonymous_usage_stats
@p.send_anonymous_usage_stats
@p.cache_selected_only
@p.debug
@p.enable_legacy_logger
Expand Down
11 changes: 4 additions & 7 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
from dbt.cli.resolvers import default_project_dir, default_profiles_dir
from dbt.version import get_version_information

# TODO: The name (reflected in flags) is a correction!
# The original name was `SEND_ANONYMOUS_USAGE_STATS` and used an env var called "DBT_SEND_ANONYMOUS_USAGE_STATS"
# Both of which break existing naming conventions (doesn't match param flag).
# This will need to be fixed before use in the main codebase and communicated as a change to the community!
anonymous_usage_stats = click.option(
"--anonymous-usage-stats/--no-anonymous-usage-stats",
envvar="DBT_ANONYMOUS_USAGE_STATS",
# TODO: Rename this to meet naming conventions (the word "send" is redundant)
send_anonymous_usage_stats = click.option(
"--send-anonymous-usage-stats/--no-send-anonymous-usage-stats",
envvar="DBT_SEND_ANONYMOUS_USAGE_STATS",
help="Send anonymous usage stats to dbt Labs.",
default=True,
)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def wrapper(*args, **kwargs):
set_flags(flags)

# Tracking
initialize_from_flags(flags.ANONYMOUS_USAGE_STATS, flags.PROFILES_DIR)
initialize_from_flags(flags.SEND_ANONYMOUS_USAGE_STATS, flags.PROFILES_DIR)
ctx.with_resource(track_run(run_command=flags.WHICH))

# Logging
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def __post_init__(self):
self.user_id = tracking.active_user.id

if self.send_anonymous_usage_stats is None:
self.send_anonymous_usage_stats = get_flags().ANONYMOUS_USAGE_STATS
self.send_anonymous_usage_stats = get_flags().SEND_ANONYMOUS_USAGE_STATS

@classmethod
def default(cls):
Expand Down
1 change: 0 additions & 1 deletion core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def get_flag_dict():
"version_check",
"fail_fast",
"send_anonymous_usage_stats",
"anonymous_usage_stats",
"printer_width",
"indirect_selection",
"log_cache_events",
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def handle_and_check(args):
# Set flags from args, user config, and env vars
user_config = read_user_config(flags.PROFILES_DIR) # This is read again later
flags.set_from_args(parsed, user_config)
dbt.tracking.initialize_from_flags(flags.ANONYMOUS_USAGE_STATS, flags.PROFILES_DIR)
dbt.tracking.initialize_from_flags(flags.SEND_ANONYMOUS_USAGE_STATS, flags.PROFILES_DIR)
# Set log_format from flags
parsed.cls.set_log_format()

Expand Down
4 changes: 2 additions & 2 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ def process(self, record):
)


def initialize_from_flags(anonymous_usage_stats, profiles_dir):
def initialize_from_flags(send_anonymous_usage_stats, profiles_dir):
# Setting these used to be in UserConfig, but had to be moved here
global active_user
if anonymous_usage_stats:
if send_anonymous_usage_stats:
active_user = User(profiles_dir)
try:
active_user.initialize()
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def test__build_flat_graph(self):
def test_metadata(self, mock_user):
mock_user.id = 'cfc9500f-dc7f-4c83-9ea7-2c581c1b38cf'
dbt.events.functions.EVENT_MANAGER.invocation_id = '01234567-0123-0123-0123-0123456789ab'
set_from_args(Namespace(ANONYMOUS_USAGE_STATS=False), None)
set_from_args(Namespace(SEND_ANONYMOUS_USAGE_STATS=False), None)
now = datetime.utcnow()
self.assertEqual(
ManifestMetadata(
Expand All @@ -450,7 +450,7 @@ def test_metadata(self, mock_user):
def test_no_nodes_with_metadata(self, mock_user):
mock_user.id = 'cfc9500f-dc7f-4c83-9ea7-2c581c1b38cf'
dbt.events.functions.EVENT_MANAGER.invocation_id = '01234567-0123-0123-0123-0123456789ab'
set_from_args(Namespace(ANONYMOUS_USAGE_STATS=False), None)
set_from_args(Namespace(SEND_ANONYMOUS_USAGE_STATS=False), None)
metadata = ManifestMetadata(
project_id='098f6bcd4621d373cade4e832627b4f6',
adapter_type='postgres',
Expand Down
1 change: 1 addition & 0 deletions tests/functional/context_methods/test_builtin_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_builtin_invocation_args_dict_function(self, project):
assert result
# The result should include a dictionary of all flags with default values that aren't None
expected = (
"'send_anonymous_usage_stats': False",
"'quiet': False",
"'print': True",
"'cache_selected_only': False",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_cli_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_anonymous_usage_state(
monkeypatch.setenv("DO_NOT_TRACK", do_not_track)

flags = Flags(run_context)
assert flags.ANONYMOUS_USAGE_STATS == expected_anonymous_usage_stats
assert flags.SEND_ANONYMOUS_USAGE_STATS == expected_anonymous_usage_stats

def test_empty_user_config_uses_default(self, run_context, user_config):
flags = Flags(run_context, user_config)
Expand Down

0 comments on commit 74dde44

Please sign in to comment.