Repository: dbt-labs/dbt-core

Issue:
DBT 0.17.0rc3 - Compilation failure regression
### Describe the bug

When trying to compile a project having some schema tests using `dbt_utils.equality` the compilation fails because the model does not exists.
However calling DBT run works.

The compilation failure happens when using DBT 0.17.0rc3, however compiling the same project using DBT 0.16.1 succeeds.

### Steps To Reproduce

The following ZIP file includes a dummy project to reproduce the issue.
[dummy.zip](https://github.com/fishtown-analytics/dbt/files/4705434/dummy.zip)

You will need to configure a profile for it though.

Extract the project and run:
```
dbt deps
dbt compile
```


### Expected behavior

The compilation succeeds on both DBT 0.16.1 and 0.17.0rc3

### Actual behavior

The compilation succeeds for DBT 0.16.1 and fails for 0.17.0rc3 with the following error:

```
Encountered an error:
Runtime Error
  Database Error in test dbt_utils_equality_my_second_dbt_model_id__ref_my_first_dbt_model_ (models/example/schema.yml)
    002003 (42S02): SQL compilation error:
    Table 'DB.SCHEMA.MY_SECOND_DBT_MODEL' does not exist or not authorized.
```

### System information
**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [ ] bigquery
- [x] snowflake
- [ ] other (specify: ____________)


**The output of `dbt --version`:**
```
dbt --version
installed version: 0.17.0-rc3
   latest version: 0.16.1

Your version of dbt is ahead of the latest release!

Plugins:
  - snowflake: 0.17.0rc3
  - postgres: 0.17.0rc3
  - redshift: 0.17.0rc3
  - bigquery: 0.17.0rc3
```

**The operating system you're using:**  Linux Mint 19.3


**The output of `python --version`:** Python 3.6.9


Discussion:
Thank you for the writeup and the _wonderful_ reproduction case! 🙏  I believe the root cause here is that we switched snowflake's `get_columns_in_relation` to use `describe table`, which results in a database error -> an exception when the relation is missing. Other adapters select from the information_schema and just return an empty list when there are no columns. The new snowflake behavior seems like a regression to me for sure!

Resolving patch:
diff --git a/plugins/snowflake/dbt/adapters/snowflake/impl.py b/plugins/snowflake/dbt/adapters/snowflake/impl.py
--- a/plugins/snowflake/dbt/adapters/snowflake/impl.py
+++ b/plugins/snowflake/dbt/adapters/snowflake/impl.py
@@ -112,6 +112,15 @@ def list_schemas(self, database: str) -> List[str]:
 
         return [row['name'] for row in results]
 
+    def get_columns_in_relation(self, relation):
+        try:
+            return super().get_columns_in_relation(relation)
+        except DatabaseException as exc:
+            if 'does not exist or not authorized' in str(exc):
+                return []
+            else:
+                raise
+
     def list_relations_without_caching(
             self, schema_relation: SnowflakeRelation
     ) -> List[SnowflakeRelation]:


Test patch:
diff --git a/test/integration/054_adapter_methods_test/test_adapter_methods.py b/test/integration/054_adapter_methods_test/test_adapter_methods.py
--- a/test/integration/054_adapter_methods_test/test_adapter_methods.py
+++ b/test/integration/054_adapter_methods_test/test_adapter_methods.py
@@ -10,22 +10,33 @@ def schema(self):
     def models(self):
         return "models"
 
+    @property
+    def project_config(self):
+        return {
+            'config-version': 2,
+            'test-paths': ['tests']
+        }
+
     @use_profile('postgres')
     def test_postgres_adapter_methods(self):
+        self.run_dbt(['compile'])  # trigger any compile-time issues
         self.run_dbt()
         self.assertTablesEqual('model', 'expected')
 
     @use_profile('redshift')
     def test_redshift_adapter_methods(self):
+        self.run_dbt(['compile'])  # trigger any compile-time issues
         self.run_dbt()
         self.assertTablesEqual('model', 'expected')
 
     @use_profile('snowflake')
     def test_snowflake_adapter_methods(self):
+        self.run_dbt(['compile'])  # trigger any compile-time issues
         self.run_dbt()
         self.assertTablesEqual('MODEL', 'EXPECTED')
 
     @use_profile('bigquery')
     def test_bigquery_adapter_methods(self):
+        self.run_dbt(['compile'])  # trigger any compile-time issues
         self.run_dbt()
         self.assertTablesEqual('model', 'expected')
diff --git a/test/integration/054_adapter_methods_test/tests/get_columns_in_relation.sql b/test/integration/054_adapter_methods_test/tests/get_columns_in_relation.sql
new file mode 100644
--- /dev/null
+++ b/test/integration/054_adapter_methods_test/tests/get_columns_in_relation.sql
@@ -0,0 +1,7 @@
+{% set columns = adapter.get_columns_in_relation(ref('model')) %}
+{% set limit_query = 0 %}
+{% if (columns | length) == 0 %}
+	{% set limit_query = 1 %}
+{% endif %}
+
+select 1 as id limit {{ limit_query }}