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 regression when an exposure references a deprecated model #10915

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Oct 24, 2024

Resolves #10911

Problem

Our current code looks like this:

child_node = self.manifest.nodes[child_unique_id]

This will raise a KeyError if child_unique_id is not found in the dictionary.

We'd want to use this if we're certain that the key will always exist, and we want an error to be raised if it doesn't. But an error is exactly opposite of what we want. Rather, we want to get None instead of an error.

Solution

Change to this code:

child_node = self.manifest.nodes.get(child_unique_id)

This will return None if child_unique_id is not found in the dictionary. Since the key might not exist, this allows us to gracefully handle it without raising an exception (i.e. checking if isinstance(child_node, ModelNode) or not).

Testing

Manually confirmed that the new test class failed without the code change ❌ and passes with the code change ✅ .

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.
  • 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.

@dbeatty10 dbeatty10 added the Skip Changelog Skips GHA to check for changelog file label Oct 24, 2024
@cla-bot cla-bot bot added the cla:yes label Oct 24, 2024
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.14%. Comparing base (bdb79e8) to head (e32ea5c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10915      +/-   ##
==========================================
- Coverage   89.20%   89.14%   -0.06%     
==========================================
  Files         183      183              
  Lines       23464    23464              
==========================================
- Hits        20930    20917      -13     
- Misses       2534     2547      +13     
Flag Coverage Δ
integration 86.43% <100.00%> (-0.13%) ⬇️
unit 62.06% <0.00%> (ø)

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

Components Coverage Δ
Unit Tests 62.06% <0.00%> (ø)
Integration Tests 86.43% <100.00%> (-0.13%) ⬇️

@dbeatty10 dbeatty10 removed the Skip Changelog Skips GHA to check for changelog file label Oct 24, 2024
@dbeatty10 dbeatty10 marked this pull request as ready for review October 24, 2024 17:43
@dbeatty10 dbeatty10 requested a review from a team as a code owner October 24, 2024 17:43
@dbeatty10 dbeatty10 changed the title Avoid a KeyError if child_unique_id is not found in the dictionary Fix regression when an exposure references a deprecated model Oct 24, 2024
@dbeatty10 dbeatty10 merged commit 8ae689c into main Oct 24, 2024
60 of 62 checks passed
@dbeatty10 dbeatty10 deleted the dbeatty/fix-10911 branch October 24, 2024 18:13
@danlsn
Copy link

danlsn commented Oct 24, 2024

At the risk of being too emotional, I really appreciate you adding my name to the changelog @dbeatty10

This is the first meaningful open-source contribution I've ever made and for it to be on a project I love so much and that our organisation completely depends on, it means a lot to me.

It might be the tiniest change ever, but nonetheless, thanks!

@Tonayya
Copy link
Contributor

Tonayya commented Oct 24, 2024

@danlsn you're a legend thanks so much for your contribution ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression] Deprecation date check raises KeyError in dbt-core & dbt Cloud
4 participants