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

ignore alternative resource types when reading partial parse cache (#2064) #2065

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,24 @@ def parse_with_cache(
old_results: Optional[ParseResult],
) -> None:
block = self._get_file(path, parser)
if not self._get_cached(block, old_results):
if not self._get_cached(block, old_results, parser):
parser.parse_file(block)

def _get_cached(
self,
block: FileBlock,
old_results: Optional[ParseResult],
parser: BaseParser,
) -> bool:
# TODO: handle multiple parsers w/ same files, by
# tracking parser type vs node type? Or tracking actual
# parser type during parsing?
if old_results is None:
return False
if old_results.has_file(block.file):
return self.results.sanitized_update(block.file, old_results)
return self.results.sanitized_update(
block.file, old_results, parser.resource_type
)
return False

def _get_file(self, path: FilePath, parser: BaseParser) -> FileBlock:
Expand Down
8 changes: 7 additions & 1 deletion core/dbt/parser/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
raise_duplicate_resource_name, raise_duplicate_patch_name,
CompilationException, InternalException
)
from dbt.node_types import NodeType
from dbt.version import __version__


Expand Down Expand Up @@ -149,7 +150,10 @@ def _process_node(
)

def sanitized_update(
self, source_file: SourceFile, old_result: 'ParseResult',
self,
source_file: SourceFile,
old_result: 'ParseResult',
resource_type: NodeType,
) -> bool:
"""Perform a santized update. If the file can't be updated, invalidate
it and return false.
Expand Down Expand Up @@ -180,6 +184,8 @@ def sanitized_update(
# the node ID could be in old_result.disabled AND in old_result.nodes.
# In that case, we have to make sure the path also matches.
for node_id in old_file.nodes:
if old_result.nodes[node_id].resource_type != resource_type:
continue
self._process_node(node_id, source_file, old_file, old_result)

for name in old_file.patches:
Expand Down
22 changes: 22 additions & 0 deletions test/integration/025_duplicate_model_test/test_duplicate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,25 @@ def test_postgres_duplicate_model_disabled_across_packages(self):
.format(schema=self.unique_schema())
result = self.run_sql(query, fetch="one")[0]
assert result == 1


class TestModelTestOverlap(DBTIntegrationTest):

@property
def schema(self):
return "duplicate_model_025"

@property
def models(self):
return "models-3"

@property
def project_config(self):
return {'test-paths': [self.models]}

@use_profile('postgres')
def test_postgres_duplicate_test_model_paths(self):
# this should be ok: test/model overlap is fine
self.run_dbt(['compile'])
self.run_dbt(['--partial-parse', 'compile'])
self.run_dbt(['--partial-parse', 'compile'])