Skip to content

Commit

Permalink
add --no-partial-parse-file-diff flag (#8361)
Browse files Browse the repository at this point in the history
* add --no-partial-parse-file-diff flag

* changelog entry

(cherry picked from commit 8350dfe)
  • Loading branch information
MichelleArk authored and github-actions[bot] committed Aug 14, 2023
1 parent 86b4409 commit 3ac3e5b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20230811-100902.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: 'add internal flag: --no-partial-parse-file-diff to inform whether to compute
a file diff during partial parsing'
time: 2023-08-11T10:09:02.832241-04:00
custom:
Author: michelleark
Issue: "8363"
1 change: 1 addition & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
@p.macro_debugging
@p.partial_parse
@p.partial_parse_file_path
@p.partial_parse_file_diff
@p.populate_cache
@p.print
@p.printer_width
Expand Down
8 changes: 8 additions & 0 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@
type=click.Path(exists=True, dir_okay=False, resolve_path=True),
)

partial_parse_file_diff = click.option(
"--partial-parse-file-diff/--no-partial-parse-file-diff",
envvar="DBT_PARTIAL_PARSE_FILE_DIFF",
help="Internal flag for whether to compute a file diff during partial parsing.",
hidden=True,
default=True,
)

populate_cache = click.option(
"--populate-cache/--no-populate-cache",
envvar="DBT_POPULATE_CACHE",
Expand Down
11 changes: 10 additions & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,17 @@ def get_full_manifest(
adapter.clear_macro_manifest()
macro_hook = adapter.connections.set_query_header

flags = get_flags()
if not flags.PARTIAL_PARSE_FILE_DIFF:
file_diff = FileDiff.from_dict(
{
"deleted": [],
"changed": [],
"added": [],
}
)
# Hack to test file_diffs
if os.environ.get("DBT_PP_FILE_DIFF_TEST"):
elif os.environ.get("DBT_PP_FILE_DIFF_TEST"):
file_diff_path = "file_diff.json"
if path_exists(file_diff_path):
file_diff_dct = read_json(file_diff_path)
Expand Down
30 changes: 28 additions & 2 deletions tests/functional/partial_parsing/test_file_diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import pytest

from dbt.tests.util import run_dbt, write_artifact
from dbt.tests.util import run_dbt, write_artifact, write_file
from tests.functional.partial_parsing.fixtures import model_one_sql, model_two_sql


first_file_diff = {
Expand All @@ -17,7 +19,7 @@
}


class TestFileDiffs:
class TestFileDiffPaths:
def test_file_diffs(self, project):

os.environ["DBT_PP_FILE_DIFF_TEST"] = "true"
Expand All @@ -35,3 +37,27 @@ def test_file_diffs(self, project):
write_artifact(second_file_diff, "file_diff.json")
results = run_dbt()
assert len(results) == 2


class TestFileDiffs:
@pytest.fixture(scope="class")
def models(self):
return {
"model_one.sql": model_one_sql,
}

def test_no_file_diffs(self, project):
# We start with a project with one model
manifest = run_dbt(["parse"])
assert len(manifest.nodes) == 1

# add a model file
write_file(model_two_sql, project.project_root, "models", "model_two.sql")

# parse without computing a file diff
manifest = run_dbt(["--partial-parse", "--no-partial-parse-file-diff", "parse"])
assert len(manifest.nodes) == 1

# default behaviour - parse with computing a file diff
manifest = run_dbt(["--partial-parse", "parse"])
assert len(manifest.nodes) == 2

0 comments on commit 3ac3e5b

Please sign in to comment.