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

Apply column quoting to unit tests #202

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented May 10, 2024

resolves #205

Note

This is just a prototype of a potential solution, and I probably won't finish it.

Anyone that wants to take it across the finish line in a separate PR and feel free to take any of it that is useful.

Problem

Unit tests do not currently take quoting of column names into account.

Solution

Make sure the locations below are all using quoted column names:

Testing

Here is a potential functional test for this scenario

dbt-tests-adapter/dbt/tests/adapter/unit_testing/test_case_sensitivity.py

import pytest
from dbt.tests.util import run_dbt


my_model_sql = """
select
    1 as {{ adapter.quote("tested_column") }},
    2 as {{ adapter.quote("TESTED_COLUMN") }},
    3 as {{ adapter.quote("TESTed_COLumn") }}
"""

test_my_model_yml = """
unit_tests:
  - name: test_my_model
    model: my_model
    given: []
    expect:
      rows:
          - {tested_column: 1, TESTED_COLUMN: 2, TESTed_COLumn: 3}
"""


class BaseUnitTestCaseSensivity:
    @pytest.fixture(scope="class")
    def models(self):
        return {
            "my_model.sql": my_model_sql,
            "unit_tests.yml": test_my_model_yml,
        }

    def test_case_sensitivity(self, project):
        results = run_dbt(["run"])
        assert len(results) == 1

        results = run_dbt(["test"])


class TestPosgresUnitTestCaseSensitivity(BaseUnitTestCaseSensivity):
    pass

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/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

@cla-bot cla-bot bot added the cla:yes label May 10, 2024
Copy link

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

This PR has been marked as Stale because it has been open with no activity as of late. If you would like the PR to remain open, please comment on the PR or else it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 11, 2024
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.

[Bug] Unit tests fail when input has a column name with a quoted identifier
1 participant