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 unit tests for incremental models with alias #10755

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

katsugeneration
Copy link
Contributor

@katsugeneration katsugeneration commented Sep 22, 2024

Resolves #10754
Resolves #10763

Problem

Solution

  • Fix this referrence name in UnitTestContext to based on alias name on incremental model

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.

@katsugeneration katsugeneration requested a review from a team as a code owner September 22, 2024 15:33
Copy link

cla-bot bot commented Sep 22, 2024

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @katsugeneration

@github-actions github-actions bot added the community This PR is from a community member label Sep 22, 2024
@katsugeneration
Copy link
Contributor Author

@cla-bot check

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

cla-bot bot commented Sep 22, 2024

The cla-bot has been summoned, and re-checked this pull request!

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.98%. Comparing base (db69473) to head (79d650b).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10755      +/-   ##
==========================================
+ Coverage   88.97%   88.98%   +0.01%     
==========================================
  Files         181      181              
  Lines       22956    22977      +21     
==========================================
+ Hits        20424    20447      +23     
+ Misses       2532     2530       -2     
Flag Coverage Δ
integration 86.16% <100.00%> (+0.02%) ⬆️
unit 62.39% <100.00%> (-0.06%) ⬇️

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

Components Coverage Δ
Unit Tests 62.39% <100.00%> (-0.06%) ⬇️
Integration Tests 86.16% <100.00%> (+0.02%) ⬆️

Copy link
Contributor

@dbeatty10 dbeatty10 left a comment

Choose a reason for hiding this comment

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

Thanks for the targeted solution and the nice functional test @katsugeneration 🤩

I can confirm that running the following test fails without the fix, but succeeds with the test in place:

python -m pytest tests/functional/unit_testing/test_unit_testing.py::TestUnitTestIncrementalModelWithAlias```

Comment on lines +276 to +291
class TestUnitTestIncrementalModelWithAlias:
@pytest.fixture(scope="class")
def models(self):
return {
"my_incremental_model.sql": my_incremental_model_with_alias_sql,
"events.sql": event_sql,
"schema.yml": test_my_model_incremental_yml_basic,
}

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

# Select by model name
results = run_dbt(["test", "--select", "my_incremental_model"], expect_pass=True)
assert len(results) == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This tests the regression reported in #10754.

I confirmed this test fails without the fix but succeeds with the fix in place:

python -m pytest tests/functional/unit_testing/test_unit_testing.py::TestUnitTestIncrementalModelWithAlias

Comment on lines +294 to +309
class TestUnitTestIncrementalModelWithVersion:
@pytest.fixture(scope="class")
def models(self):
return {
"my_incremental_model.sql": my_incremental_model_sql,
"events.sql": event_sql,
"schema.yml": my_incremental_model_versioned_yml + test_my_model_incremental_yml_basic,
}

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

# Select by model name
results = run_dbt(["test", "--select", "my_incremental_model"], expect_pass=True)
assert len(results) == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This tests the regression reported in #10763.

I confirmed this test fails without the fix but succeeds with the fix in place:

python -m pytest tests/functional/unit_testing/test_unit_testing.py::TestUnitTestIncrementalModelWithVersion

@@ -1636,7 +1636,7 @@ def this(self) -> Optional[str]:
if self.model.this_input_node_unique_id:
this_node = self.manifest.expect(self.model.this_input_node_unique_id)
self.model.set_cte(this_node.unique_id, None) # type: ignore
return self.adapter.Relation.add_ephemeral_prefix(this_node.name)
return self.adapter.Relation.add_ephemeral_prefix(this_node.identifier) # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

The root causes of the regressions reported in #10754 and #10763 was that:

  1. the update from this_node.name to this_node.identifier was accidentally overlooked during the implementation and code review of https://github.com/dbt-labs/dbt-core/pull/10290/files, and
  2. there were no functional tests to catch those particular cases

This PR addresses both of those root causes ✅ ✅

@MichelleArk MichelleArk merged commit a8d4ba2 into dbt-labs:main Sep 24, 2024
60 checks passed
dbeatty10 pushed a commit that referenced this pull request Sep 24, 2024
dbeatty10 added a commit that referenced this pull request Sep 27, 2024
(cherry picked from commit a8d4ba2)

Co-authored-by: Katsuya Shimabukuro <[email protected]>
Co-authored-by: Gerda Shank <[email protected]>
@rmbborges
Copy link

Hey @dbeatty10 , will this fix be included in 1.8.8?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.8.latest cla:yes community This PR is from a community member
Projects
None yet
4 participants