Repository: dbt-labs/dbt-core

Issue:
bigquery__create_schema macro takes the wrong arguments
### Describe the bug
create schema is defined like this:
```
{% macro create_schema(relation) -%}
  {{ adapter_macro('create_schema', relation) }}
{% endmacro %}
```
but I missed bigquery:
```
{% macro bigquery__create_schema(database_name, schema_name) -%}
  {{ adapter.create_schema(database_name, schema_name) }}
{% endmacro %}
```

I introduced this in 0.17.0rc1. Also, tests would be smart!

I think this is a pretty minor issue, not many people are calling the `create_schema` macro, it's really only there for completeness. But still, it should work.

### Steps To Reproduce
1) Be on bigquery
2) call `create_schema(relation)`

### Expected behavior
Macros should work

### System information
**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [X] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)


Discussion:

Resolving patch:
diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py
--- a/core/dbt/context/providers.py
+++ b/core/dbt/context/providers.py
@@ -234,7 +234,11 @@ def _validate(self, validator, value):
         validator(value)
 
     def _lookup(self, name, default=_MISSING):
-        result = self.model.config.get(name, default)
+        # if this is a macro, there might be no `model.config`.
+        if not hasattr(self.model, 'config'):
+            result = default
+        else:
+            result = self.model.config.get(name, default)
         if result is _MISSING:
             missing_config(self.model, name)
         return result
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
@@ -212,6 +212,7 @@ def expand_target_column_types(
         # This is a no-op on BigQuery
         pass
 
+    @available.parse_list
     def list_relations_without_caching(
         self, schema_relation: BigQueryRelation
     ) -> List[BigQueryRelation]:


Test patch:
diff --git a/test/integration/022_bigquery_test/macros/wrapped_macros.sql b/test/integration/022_bigquery_test/macros/wrapped_macros.sql
new file mode 100644
--- /dev/null
+++ b/test/integration/022_bigquery_test/macros/wrapped_macros.sql
@@ -0,0 +1,43 @@
+{% macro my_create_schema(db_name, schema_name) %}
+    {% if not execute %}
+        {% do return(None) %}
+    {% endif %}
+    {% set relation = api.Relation.create(database=db_name, schema=schema_name).without_identifier() %}
+    {% do create_schema(relation) %}
+{% endmacro %}
+
+{% macro my_drop_schema(db_name, schema_name) %}
+    {% if not execute %}
+        {% do return(None) %}
+    {% endif %}
+    {% set relation = api.Relation.create(database=db_name, schema=schema_name).without_identifier() %}
+    {% do drop_schema(relation) %}
+{% endmacro %}
+
+
+{% macro my_create_table_as(db_name, schema_name, table_name) %}
+    {% if not execute %}
+        {% do return(None) %}
+    {% endif %}
+    {% set relation = api.Relation.create(database=db_name, schema=schema_name, identifier=table_name) %}
+    {% do run_query(create_table_as(false, relation, 'select 1 as id')) %}
+{% endmacro %}
+
+
+{% macro ensure_one_relation_in(db_name, schema_name) %}
+    {% if not execute %}
+        {% do return(None) %}
+    {% endif %}
+    {% set relation = api.Relation.create(database=db_name, schema=schema_name).without_identifier() %}
+    {% set results = list_relations_without_caching(relation) %}
+    {% set rlen = (results | length) %}
+    {% if rlen != 1 %}
+        {% do exceptions.raise_compiler_error('Incorect number of results (expected 1): ' ~ rlen) %}
+    {% endif %}
+    {% set result = results[0] %}
+    {% set columns = get_columns_in_relation(result) %}
+    {% set clen = (columns | length) %}
+    {% if clen != 1 %}
+        {% do exceptions.raise_compiler_error('Incorrect number of columns (expected 1): ' ~ clen) %}
+    {% endif %}
+{% endmacro %}
diff --git a/test/integration/022_bigquery_test/test_bigquery_adapter_functions.py b/test/integration/022_bigquery_test/test_bigquery_adapter_functions.py
--- a/test/integration/022_bigquery_test/test_bigquery_adapter_functions.py
+++ b/test/integration/022_bigquery_test/test_bigquery_adapter_functions.py
@@ -1,4 +1,5 @@
 from test.integration.base import DBTIntegrationTest, FakeArgs, use_profile
+import yaml
 
 
 class TestBigqueryAdapterFunctions(DBTIntegrationTest):
@@ -29,3 +30,42 @@ def test__bigquery_adapter_functions(self):
             # status = # of failing rows
             self.assertEqual(result.status, 0)
 
+
+class TestBigqueryAdapterMacros(DBTIntegrationTest):
+    @property
+    def schema(self):
+        return "bigquery_test_022"
+
+    @property
+    def models(self):
+        return "models"
+
+    def _create_schema_named(self, database, schema):
+        # do not create the initial schema. We'll do this ourselves!
+        pass
+
+    @use_profile('bigquery')
+    def test__bigquery_run_create_drop_schema(self):
+        schema_args = yaml.safe_dump({
+            'db_name': self.default_database,
+            'schema_name': self.unique_schema(),
+        })
+        self.run_dbt(['run-operation', 'my_create_schema', '--args', schema_args])
+        relation_args = yaml.safe_dump({
+            'db_name': self.default_database,
+            'schema_name': self.unique_schema(),
+            'table_name': 'some_table',
+        })
+        self.run_dbt(['run-operation', 'my_create_table_as', '--args', relation_args])
+        # exercise list_relations_without_caching and get_columns_in_relation
+        self.run_dbt(['run-operation', 'ensure_one_relation_in', '--args', schema_args])
+        # now to drop the schema
+        schema_relation = self.adapter.Relation.create(database=self.default_database, schema=self.unique_schema()).without_identifier()
+        with self.adapter.connection_named('test'):
+            results = self.adapter.list_relations_without_caching(schema_relation)
+        assert len(results) == 1
+
+        self.run_dbt(['run-operation', 'my_drop_schema', '--args', schema_args])
+        with self.adapter.connection_named('test'):
+            results = self.adapter.list_relations_without_caching(schema_relation)
+        assert len(results) == 0