Repository: dbt-labs/dbt-core

Issue:
dbt fails if destination schema contains a LOCAL TEMPORARY in Snowflake
### Describe the bug
dbt fails to compile or run when the destination schema contains a LOCAL TEMPORARY table

### Steps To Reproduce
Run `dbt compile` while someone else is running `dbt run`

### Expected behavior
No error occurs.

### Screenshots and log output
```
Running with dbt=0.14.3

* Deprecation Warning: The adapter function `adapter.already_exists` is deprecated and will be removed in
 a future release of dbt. Please use `adapter.get_relation` instead.
 Documentation for get_relation can be found here:
 https://docs.getdbt.com/docs/adapter

Unhandled error while executing model.snowflake.inventory
connection never acquired for thread (15906, 123145576628224), have []
Encountered an error:
Runtime Error
  Runtime Error in model inventory (models/inventory.sql)
    Invalid arguments passed to "SnowflakeRelation" instance: type.'LOCAL TEMPORARY' is not one of ['table', 'view', 'cte', 'materializedview', 'externaltable', None]
```

### System information
**Database:** Snowflake

**The output of `dbt --version`:** 0.14.3

**The operating system you're using:** OS X

**The output of `python --version`:** 3.7

### Additional context
While we don't have any tables explicitly specified as LOCAL TEMPORARY, we believe this is happening because other processes are running dbt and LOCAL TEMPORARY tables are being created in the process of merging or replacing the tables.  As such, the specific tables that throw the error are different each time we encounter this error.  When we look in the information schema after getting this error, the LOCAL TEMPORARY tables reported in the error text are shown as regular tables.

Similar to the fix for https://github.com/fishtown-analytics/dbt/pull/1431, we created a fork and added a `LOCAL TEMPORARY` relation type which seems to have fixed the issue.  We wanted to report the issue here as well.


Discussion:

Resolving patch:
diff --git a/core/dbt/adapters/base/relation.py b/core/dbt/adapters/base/relation.py
--- a/core/dbt/adapters/base/relation.py
+++ b/core/dbt/adapters/base/relation.py
@@ -147,14 +147,6 @@ def __eq__(self, other):
     def get_default_quote_policy(cls: Type[Self]) -> Policy:
         return cls._get_field_named('quote_policy').default
 
-    @classmethod
-    def get_default_include_policy(cls: Type[Self]) -> Policy:
-        return cls._get_field_named('include_policy').default
-
-    @classmethod
-    def get_relation_type_class(cls: Type[Self]) -> Type[RelationType]:
-        return cls._get_field_named('type')
-
     def get(self, key, default=None):
         """Override `.get` to return a metadata object so we don't break
         dbt_utils.
diff --git a/core/dbt/adapters/sql/impl.py b/core/dbt/adapters/sql/impl.py
--- a/core/dbt/adapters/sql/impl.py
+++ b/core/dbt/adapters/sql/impl.py
@@ -196,6 +196,10 @@ def list_relations_without_caching(self, information_schema, schema):
             'identifier': True
         }
         for _database, name, _schema, _type in results:
+            try:
+                _type = self.Relation.RelationType(_type)
+            except ValueError:
+                _type = self.Relation.RelationType.External
             relations.append(self.Relation.create(
                 database=_database,
                 schema=_schema,
diff --git a/plugins/bigquery/dbt/adapters/bigquery/impl.py b/plugins/bigquery/dbt/adapters/bigquery/impl.py
--- a/plugins/bigquery/dbt/adapters/bigquery/impl.py
+++ b/plugins/bigquery/dbt/adapters/bigquery/impl.py
@@ -294,7 +294,10 @@ def _bq_table_to_relation(self, bq_table):
                 'schema': True,
                 'identifier': True
             },
-            type=self.RELATION_TYPES.get(bq_table.table_type))
+            type=self.RELATION_TYPES.get(
+                bq_table.table_type, RelationType.External
+            ),
+        )
 
     @classmethod
     def warning_on_hooks(hook_type):


Test patch: