Repository: dbt-labs/dbt-core

Issue:
[CT-1824] [Bug] Python models do not respect quoting for `dbt.this()`
### Is this a new bug in dbt-core?

- [X] I believe this is a new bug in dbt-core
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

`dbt.this()` should provide access to the full stringified relation name, including quotes (or not) depending on the project- and adapter-level `quoting` config.

This is important especially for incremental modeling logic, which needs the ability to template the preexisting table name into the model code:
```python
    if dbt.is_incremental:

        # only new rows compared to max in current table
        max_from_this = f"select max(updated_at) from {dbt.this}"
        df = df.filter(df.updated_at >= session.sql(max_from_this).collect()[0][0])

        # or only rows from the past 3 days
        df = df.filter(df.updated_at >= F.date_add(F.current_timestamp(), F.lit(-3)))
```

In the current compiled code, `dbt.this()` doesn't include quotes:
```
class this:
    """dbt.this() or dbt.this.identifier"""
    database = 'project-name'
    schema = 'dbt_jcohen'
    identifier = 'python_model'
    def __repr__(self):
        return 'project-name.dbt_jcohen.python_model'
```

So users have to resort to hacks like:
```
          this = "`".join(str(dbt.this).split("."))
          this = f"`{dbt.this.database}`.`{dbt.this.schema}`.`{dbt.this.identifier}`"
```

### Expected Behavior

While `dbt.this.<partname>` should return the unquoted value, `dbt.this()` should return the full rendered relation name, with (or without) quoting as appropriate:
```python
class this:
    """dbt.this() or dbt.this.identifier"""
    database = 'dbt-test-env'
    schema = 'dbt_jcohen'
    identifier = 'python_model'
    def __repr__(self):
        return '`dbt-test-env`.`dbt_jcohen`.`python_model`'
```

### Steps To Reproduce

1. Create a Python model on `dbt-bigquery` in a hyphenated project/dataset name
2. Try to materialize it incrementally, per [our docs](https://docs.getdbt.com/docs/build/python-models#materializations)
3. It fails because the relation name needs to be quoted

### Relevant log output

_No response_

### Environment

```markdown
- OS: 12.6.2
- Python: 3.10.9
- dbt: 1.3.2
```


### Which database adapter are you using with dbt?

bigquery

### Additional Context

[Slack thread](https://getdbt.slack.com/archives/C03QUA7DWCW/p1671045654467469)

Related issues:
- https://github.com/dbt-labs/dbt-core/issues/6103
- https://github.com/dbt-labs/dbt-snowflake/issues/330


Discussion:

Resolving patch:
diff --git a/core/dbt/compilation.py b/core/dbt/compilation.py
--- a/core/dbt/compilation.py
+++ b/core/dbt/compilation.py
@@ -351,13 +351,6 @@ def _compile_node(
         )
 
         if node.language == ModelLanguage.python:
-            # TODO could we also 'minify' this code at all? just aesthetic, not functional
-
-            # quoating seems like something very specific to sql so far
-            # for all python implementations we are seeing there's no quating.
-            # TODO try to find better way to do this, given that
-            original_quoting = self.config.quoting
-            self.config.quoting = {key: False for key in original_quoting.keys()}
             context = self._create_node_context(node, manifest, extra_context)
 
             postfix = jinja.get_rendered(
@@ -367,8 +360,6 @@ def _compile_node(
             )
             # we should NOT jinja render the python model's 'raw code'
             node.compiled_code = f"{node.raw_code}\n\n{postfix}"
-            # restore quoting settings in the end since context is lazy evaluated
-            self.config.quoting = original_quoting
 
         else:
             context = self._create_node_context(node, manifest, extra_context)


Test patch: