Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Source quoting ignores global configuration #10905

Merged
merged 11 commits into from
Oct 25, 2024

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Oct 22, 2024

Resolves #10892 (regression)

Problem

In dbt-core 1.7 and earlier, quoting behavior for sources was not controlled by the quoting configuration in dbt_project.yml, but newer versions of dbt also apply those settings to sources.

Solution

For sources, pass along an 'empty' quoting config as the base config, ignoring anything that's in self.config.quoting (ie dbt_project.yml). This was effectively the case in versions <1.7, which used create_from_source which did not incorporate the config quoting like create_from_node did.

⚠️ Note:
We are not putting this behind a behaviour flag because:

  • This behaviour was previously intentional and documented (here and here). The quoting: config in the dbt_project.yml file is just for creating relations / resolving a ref, and this is truly addressing a regression
  • It is highly unlikely that restoring the previous behaviour will cause any issues in existing projects that may be depending on the quoting config being ignored. By default and in most adapters other than snowflake, quoting is True by default, so sources getting opted into quoting has not been problematic. It's only on snowflake that the regression has been raised because it is False by default, and adding quotes has been unsafe to do by default for sources when they otherwise wouldn't have been.
    • In either case, the current behaviour goes counter to our documentation and would not have been safe to rely on.
  • We don't want to phase in the new behaviour / deprecate the old behavior. From @jtcohen6:
    • people should be specifically configuring sources with nonstandard quoting, so for those people this should be no change (and the previous behavior is more desirable)

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@cla-bot cla-bot bot added the cla:yes label Oct 22, 2024
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.14%. Comparing base (f7b7935) to head (2843876).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10905      +/-   ##
==========================================
- Coverage   89.15%   89.14%   -0.02%     
==========================================
  Files         183      183              
  Lines       23443    23466      +23     
==========================================
+ Hits        20901    20919      +18     
- Misses       2542     2547       +5     
Flag Coverage Δ
integration 86.43% <100.00%> (-0.01%) ⬇️
unit 62.06% <100.00%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.06% <100.00%> (-0.06%) ⬇️
Integration Tests 86.43% <100.00%> (-0.01%) ⬇️

return self.Relation.create_from(
self.config,
SourceQuotingConfig(),
Copy link
Contributor Author

@MichelleArk MichelleArk Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative approach would be to extend BaseRelation.create_from to accept an Optional[HasQuoting] value instead of just HasQuoting. That said, the method in dbt-adapters is:

  • abstracted to the point where it does not concern itself with the node type (e.g. model vs seed vs source, etc), and this kind of business logic feels better-suited in dbt-core
  • overridable across adapters, so could lead to inconsistent handling + need updates across multiple adapters for consistent behaviour

So I went with this approach. Open to feedback :) I opted to define SourceQuotingBaseConfig inline here since it quite specialized and likely won't need to be used elsewhere in the codebase.

@MichelleArk MichelleArk changed the title Source quoting ignores global configuration Fix: Source quoting ignores global configuration Oct 24, 2024

generated_sql = read_file("target", "compiled", "test", "models", "model.sql")
assert generated_sql == 'select * from "source_database"."source_schema"."customers"'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed the above test does fail on main as expected:

tests/functional/relation_quoting/test_relation_quoting.py F.                                                                                         [100%]

========================================================================= FAILURES ==========================================================================
_________________________________________ TestSourceQuotingGlobalConfigs.test_sources_ignore_global_quoting_configs _________________________________________

self = <test_relation_quoting.TestSourceQuotingGlobalConfigs object at 0x114bdba30>
project = <dbt.tests.fixtures.project.TestProjInfo object at 0x115b1e9b0>

    def test_sources_ignore_global_quoting_configs(self, project):
        run_dbt(["compile"])
    
        generated_sql = read_file("target", "compiled", "test", "models", "model.sql")
>       assert generated_sql == 'select * from "source_database"."source_schema"."customers"'
E       assert 'select * fro...ema.customers' == 'select * fro..."."customers"'
E         - select * from "source_database"."source_schema"."customers"
E         ?               -               - -             - -         -
E         + select * from source_database.source_schema.customers

/Users/michelleark/src/dbt-core/tests/functional/relation_quoting/test_relation_quoting.py:38: AssertionError
------------------------------------------------------------------- Captured stdout setup -------------------------

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have also confirmed these tests pass with no code changes on 1.7.latest: #10906

@MichelleArk MichelleArk marked this pull request as ready for review October 24, 2024 21:41
@MichelleArk MichelleArk requested a review from a team as a code owner October 24, 2024 21:41
@MichelleArk MichelleArk merged commit 316ecfc into main Oct 25, 2024
67 checks passed
@MichelleArk MichelleArk deleted the source-quoting-ignores-global-configuration branch October 25, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression] Quoting behavior for sources
2 participants