Skip to content

Commit

Permalink
Merge pull request #2065 from fishtown-analytics/fix/ignore-alternati…
Browse files Browse the repository at this point in the history
…ve-resource-types

ignore alternative resource types when reading partial parse cache (#2064)
  • Loading branch information
beckjake committed Jan 24, 2020
2 parents 66a4f76 + 760d46a commit 0b8f3bc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
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'])

0 comments on commit 0b8f3bc

Please sign in to comment.