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

[Bug] dbt-loom does not inject models appropriately for unit tests to function. #84

Open
nicholasyager opened this issue Sep 6, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@nicholasyager
Copy link
Owner

Describe the bug

If a unit test is created in a downstream project, and the test references a model in another project, dbt-core will yield a Compilation Error.

To Reproduce
Steps to reproduce the behavior:

  1. In the customer_success test project, add a unit test to customers.
    unit_tests:
     - name: test_customer_type_mapping
       description: >
         Confirm that customer types are mapped corrected based on repeat buying behavior.
       model: customers
       given:
         - input: ref('stg_customers')
           rows:
             - { customer_id: 1, foo: "bar" }
    
         - input: ref('orders')
           rows:
             - {
                 customer_id: 1,
                 ordered_at: "2024-01-01T00:00:00Z",
                 subtotal: 1.50,
                 order_total: 5.50,
               }
             - {
                 customer_id: 1,
                 ordered_at: "2024-01-02T00:00:00Z",
                 subtotal: 2.00,
                 order_total: 5.50,
               }
    
       expect:
         rows:
           - {
               customer_id: 1,
               foo: "bar",
               count_lifetime_orders: 2,
               customer_type: "returning",
             }
  2. In customer_success, run dbt build
  3. See the following error.
dbt-loom-py3.12> $ dbt build                                                                                                                                                                                                                                                                                                                                                                                                                                                          [±main ●(✹)]
12:59:41  Running with dbt=1.8.0
12:59:41  Initializing dbt-loom=0.5.2
12:59:41  dbt-loom: Patching ref protection methods to support dbt-loom dependencies.
12:59:41  dbt-loom: Loading manifest for `revenue` from `file`
12:59:41  Registered adapter: duckdb=1.8.0
12:59:41  dbt-loom: Injecting nodes
12:59:41  [WARNING]: Model orders.v1 has passed its deprecation date of 2024-01-01T00:00:00-05:00. This model should be disabled or removed.
12:59:41  Found 13 models, 5 data tests, 1 source, 519 macros, 1 unit test
12:59:41  
12:59:42  Concurrency: 4 threads (target='dev')
12:59:42  
12:59:42  1 of 8 START sql view model main.stg_customers ................................. [RUN]
12:59:42  1 of 8 OK created sql view model main.stg_customers ............................ [OK in 0.07s]
12:59:42  2 of 8 START test not_null_stg_customers_customer_id ........................... [RUN]
12:59:42  3 of 8 START test unique_stg_customers_customer_id ............................. [RUN]
12:59:42  3 of 8 PASS unique_stg_customers_customer_id ................................... [PASS in 0.06s]
12:59:42  2 of 8 PASS not_null_stg_customers_customer_id ................................. [PASS in 0.07s]
12:59:42  4 of 8 START unit_test customers::test_customer_type_mapping ................... [RUN]
12:59:42  4 of 8 ERROR customers::test_customer_type_mapping ............................. [ERROR in 0.03s]
12:59:42  5 of 8 SKIP relation main.customers ............................................ [SKIP]
12:59:42  6 of 8 SKIP test accepted_values_customers_customer_type__new__returning ....... [SKIP]
12:59:42  7 of 8 SKIP test not_null_customers_customer_id ................................ [SKIP]
12:59:42  8 of 8 SKIP test unique_customers_customer_id .................................. [SKIP]
12:59:42  
12:59:42  Finished running 1 view model, 5 data tests, 1 unit test, 1 table model in 0 hours 0 minutes and 0.31 seconds (0.31s).
12:59:42  
12:59:42  Completed with 1 error and 0 warnings:
12:59:42  
12:59:42    Compilation Error in unit_test test_customer_type_mapping (models/marts/__models.yml)
  Unit_Test 'unit_test.customer_success.customers.test_customer_type_mapping' (models/marts/__models.yml) depends on a node named 'orders' in package or project 'revenue' which was not found
12:59:42  
12:59:42  Done. PASS=3 WARN=0 ERROR=1 SKIP=4 TOTAL=8

Expected behavior
A clear and concise description of what you expected to happen.

dbt-loom should inject dependencies early enough in the process to allow unit tests to leverage injected models.

Screenshots
If applicable, add screenshots to help explain your problem.

  • OS: MacOS 14.5
  • dbt-loom Version: 0.5.7
  • dbt-core Version: 1.8.0

Additional context
Add any other context about the problem here.

@nicholasyager nicholasyager added bug Something isn't working triage This issue is being investigated labels Sep 6, 2024
@nicholasyager nicholasyager self-assigned this Sep 6, 2024
@nicholasyager nicholasyager changed the title [Bug] dbt-loom does not inject unit tests appropriately for unit tests to function. [Bug] dbt-loom does not inject models appropriately for unit tests to function. Sep 6, 2024
@nicholasyager nicholasyager removed the triage This issue is being investigated label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant