Repository: dbt-labs/dbt-core

Issue:
Partial parsing: duplicate resource error
### Describe the bug
When the `--partial-parse` flag is enable, dbt can fail with an errant compilation error:

```
$ dbt --partial-parse compile
Running with dbt=0.15.0
Encountered an error:
Compilation Error
  dbt found two resources with the name "adwords_ad_performance_adapter". Since these resources have the same name,
  dbt will be unable to find the correct resource when ref("adwords_ad_performance_adapter") is used. To fix this,
  change the name of one of these resources:
  - model.adwords.adwords_ad_performance_adapter (models/router/adapter/criteria/adwords_ad_performance_adapter.sql)
  - model.adwords.adwords_ad_performance_adapter (models/router/adapter/criteria/adwords_ad_performance_adapter.sql)
```

dbt is reporting the same model twice. Interestingly, there actually _are_ two instances of models named `adwords_ad_performance_adapter` in the [adwords package](https://github.com/fishtown-analytics/adwords):
 - https://github.com/fishtown-analytics/adwords/blob/master/models/router/adapter/criteria/adwords_ad_performance_adapter.sql
 - https://github.com/fishtown-analytics/adwords/blob/master/models/router/adapter/url/adwords_ad_performance_adapter.sql

These models are conditionally enabled using a variable, `adapter_value`, defined in the `dbt_project.yml` file.

It's not yet clear to me if dbt is failing because it's finding both of these models and reporting an errant error message, or if dbt really is picking up the same model twice somehow.

### Steps To Reproduce

Add the following to `packages.yml`:
```
packages:
  - package: fishtown-analytics/adwords
    version: 0.2.9
```

Add the following to `dbt_project.yml`:
```
models:
    adwords:
        vars:
            adapter_value: criteria
```

Create a model called `adwords_criteria_performance.sql` with the contents:
```
select 1 as id
```

```
# Succeeds
$ dbt compile

# Fails with duplicate model error
$ dbt --partial-parse compile
```

### Expected behavior
dbt should compile and run this project successfully.

**The output of `dbt --version`:**
```
dbt v0.15.0
```


Discussion:

Resolving patch:
diff --git a/core/dbt/parser/results.py b/core/dbt/parser/results.py
--- a/core/dbt/parser/results.py
+++ b/core/dbt/parser/results.py
@@ -117,6 +117,37 @@ def _get_disabled(
             if n.original_file_path == match_file.path.original_file_path
         ]
 
+    def _process_node(
+        self,
+        node_id: str,
+        source_file: SourceFile,
+        old_file: SourceFile,
+        old_result: 'ParseResult',
+    ) -> None:
+        """Nodes are a special kind of complicated - there can be multiple
+        with the same name, as long as all but one are disabled.
+        """
+        source_path = source_file.path.original_file_path
+        found: bool = False
+        if node_id in old_result.nodes:
+            old_node = old_result.nodes[node_id]
+            if old_node.original_file_path == source_path:
+                self.add_node(source_file, old_node)
+                found = True
+
+        if node_id in old_result.disabled:
+            matches = old_result._get_disabled(node_id, source_file)
+            for match in matches:
+                self.add_disabled(source_file, match)
+                found = True
+
+        if not found:
+            raise CompilationException(
+                'Expected to find "{}" in cached "manifest.nodes" or '
+                '"manifest.disabled" based on cached file information: {}!'
+                .format(node_id, old_file)
+            )
+
     def sanitized_update(
         self, source_file: SourceFile, old_result: 'ParseResult',
     ) -> bool:
@@ -146,20 +177,10 @@ def sanitized_update(
         # because we know this is how we _parsed_ the node, we can safely
         # assume if it's disabled it was done by the project or file, and
         # we can keep our old data
+        # 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 node_id in old_result.nodes:
-                node = old_result.nodes[node_id]
-                self.add_node(source_file, node)
-            elif node_id in old_result.disabled:
-                matches = old_result._get_disabled(node_id, source_file)
-                for match in matches:
-                    self.add_disabled(source_file, match)
-            else:
-                raise CompilationException(
-                    'Expected to find "{}" in cached "manifest.nodes" or '
-                    '"manifest.disabled" based on cached file information: {}!'
-                    .format(node_id, old_file)
-                )
+            self._process_node(node_id, source_file, old_file, old_result)
 
         for name in old_file.patches:
             patch = _expect_value(


Test patch:
diff --git a/test/integration/025_duplicate_model_test/test_duplicate_model.py b/test/integration/025_duplicate_model_test/test_duplicate_model.py
--- a/test/integration/025_duplicate_model_test/test_duplicate_model.py
+++ b/test/integration/025_duplicate_model_test/test_duplicate_model.py
@@ -83,7 +83,17 @@ def test_postgres_duplicate_model_disabled(self):
         query = "select value from {schema}.model" \
                 .format(schema=self.unique_schema())
         result = self.run_sql(query, fetch="one")[0]
-        assert result == 1
+        self.assertEqual(result, 1)
+
+    @use_profile('postgres')
+    def test_postgres_duplicate_model_disabled_partial_parsing(self):
+        self.run_dbt(['clean'])
+        results = self.run_dbt(["--partial-parse", "run"])
+        self.assertEqual(len(results), 1)
+        results = self.run_dbt(["--partial-parse", "run"])
+        self.assertEqual(len(results), 1)
+        results = self.run_dbt(["--partial-parse", "run"])
+        self.assertEqual(len(results), 1)
 
 
 class TestDuplicateModelEnabledAcrossPackages(DBTIntegrationTest):