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

Ensure unit test models can depend on external nodes #9343

Merged

Conversation

QMalcolm
Copy link
Contributor

@QMalcolm QMalcolm commented Jan 5, 2024

resolves #8944

Problem

We weren't sure if external nodes were already supported in unit test nodes. This PR added tests that identified that unit test nodes didn't have full support for external nodes, and then made the necessary changes to support them.

Solution

  • Update all models in a unit test node's shadow manifest have a path for file writing
  • Update unit test parsing to ensure models keep their original package name
  • Altered the packages_for_node to gracefully allow for unknown dependencies

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
  • This PR includes type annotations for new and modified functions

@QMalcolm QMalcolm added the Skip Changelog Skips GHA to check for changelog file label Jan 5, 2024
@cla-bot cla-bot bot added the cla:yes label Jan 5, 2024
@QMalcolm QMalcolm changed the base branch from main to unit_testing_feature_branch January 5, 2024 20:09
@QMalcolm QMalcolm changed the title Ensur unit test models can depend on external nodes Ensure unit test models can depend on external nodes Jan 5, 2024
Copy link

codecov bot commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0da5dfe) 86.93% compared to head (18abef2) 86.94%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9343   +/-   ##
=======================================
  Coverage   86.93%   86.94%           
=======================================
  Files         187      187           
  Lines       24954    24953    -1     
=======================================
+ Hits        21695    21696    +1     
+ Misses       3259     3257    -2     
Flag Coverage Δ
integration 84.32% <100.00%> (+<0.01%) ⬆️
unit 63.24% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from unit_testing_feature_branch to main January 16, 2024 22:37
@QMalcolm QMalcolm force-pushed the qmalcolm--8944-unit-test-models-dependent-on-external-nodes branch from 7fa5e5c to 24114a3 Compare January 16, 2024 23:27
… postgres max

Was getting test failures due to resulting lengthy model names being created
by unit test task in the functional test
…external node point to it

Previously I was getting an error about the columns for the external model
not being fetchable from the database via the macro `get_columns_in_relation`.
By creating a seed for the tests, which creates a table in postgres, we can then
tell the external model that it's database schema and identifier (the relation)
is that table from the seed without make the seed an actual dependency of the
external model in the dag.
External nodes generally don't have paths, but in unit tests we write out
all models to sql files (as this allows us to test them). Thus external
nodes need to have their paths set.
This is necessary because when executing a unit tests, the columns
associated with a model in the database are retrieved. For this to
be possible, the model must exist in the database, thus we must
run the associated models at least once first.
@QMalcolm QMalcolm force-pushed the qmalcolm--8944-unit-test-models-dependent-on-external-nodes branch from 24114a3 to b57a7f7 Compare January 18, 2024 18:34
…an external node

Previously we were only pseudo creating an external package for testing
how unit tests work with external nodes. This was problematic because the
package didn't actually exist and thus wasn't seen as accessible when running
through dag dependencies. By actually creating the external package, we
ensure that all the built in normal processes happen.
@QMalcolm QMalcolm force-pushed the qmalcolm--8944-unit-test-models-dependent-on-external-nodes branch from d9774b8 to adeb324 Compare January 19, 2024 00:37
By flipping the logic from `not in` to `in` we can drop the exception
and instead default to the model runtime config when the package isn't
found. We're still trying to grok if there will be any fallout from this.
The tests all pass, but that doesn't guarantee nothing bad will happen.
@QMalcolm QMalcolm removed the Skip Changelog Skips GHA to check for changelog file label Jan 19, 2024
@QMalcolm QMalcolm marked this pull request as ready for review January 19, 2024 16:14
@QMalcolm QMalcolm requested a review from a team as a code owner January 19, 2024 16:14
@QMalcolm QMalcolm requested a review from gshank January 19, 2024 16:14
Copy link
Contributor

@gshank gshank left a comment

Choose a reason for hiding this comment

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

Looks good!

raise PackageNotInDepsError(package_name, node=self._node)
yield dependencies[package_name]
if package_name in dependencies:
yield dependencies[package_name]
Copy link
Contributor

@MichelleArk MichelleArk Jan 22, 2024

Choose a reason for hiding this comment

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

For posterity, thinking out loud about the implications of this change:

  • This method is used to load the vars available for a particular jinja (model-scoped) context via the vars macro.
  • This method falls back on the running project's vars if the node has no associated packages. If it returns the wrong package -- this could lead to a 'no var found' issue at runtime.
  • Before external models, it was not possible to have a model node exist in the project without a corresponding package, which is probably why this code path was not reachable
  • With external nodes, this is totally possible now -- so explicitly supporting both paths feels totally reasonable, and correct!

@QMalcolm QMalcolm merged commit eecaee1 into main Jan 22, 2024
52 checks passed
@QMalcolm QMalcolm deleted the qmalcolm--8944-unit-test-models-dependent-on-external-nodes branch January 22, 2024 17:04
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.

[CT-3291] [Feature] unit test models that depend on external nodes
3 participants