Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Dec 16, 2025

Summary

Fixes test ownership attribution to only collect owners from the primary model being tested, rather than aggregating owners from ALL parent models that a test references.

Before: A relationship test between model_a (owner: Alice) and model_b (owner: Bob) would show both owners.

After: The same test only shows the primary model's owner (the model specified in the test's model parameter).

Changes

  • Removed owner collection from the parent models loop (kept tag collection unchanged)
  • Added owner extraction inside the if tested_model_node: block, using the same parsing pattern from flatten_model
  • Restored | unique | list deduplication filter to ensure no duplicate owners appear in model_owners
  • Edge cases handled: when primary model ID is None or tested model node is None, test_models_owners remains empty

Updates since last revision

  • Added integration tests in test_test_owners.py covering:
    • Single-parent test owner attribution (baseline case)
    • Relationship test uses primary model owner only (key CORE-196 validation)
    • Relationship test with no owner on primary model (edge case)
    • Owner deduplication (validates the | unique | list fix)
  • Addressed CodeRabbit review comments:
    • Fixed JSON parsing bug in _parse_model_owners: now returns [parsed] instead of [model_owners_value] when json.loads() succeeds with a non-list value
    • Removed unused tmp_path parameter from all 4 test functions
  • Addressed reviewer feedback on test code quality:
    • Added type hints to all helper functions (cleanup_file, _parse_model_owners) and test functions
    • Created _create_model_sql utility function to reduce code duplication
  • Fixed dbt fusion compatibility:
    • Used arguments format for relationship test YAML definitions
    • Added @pytest.mark.skip_for_dbt_fusion to relationship tests (fusion handles primary model detection differently, causing empty model_owners)

Review & Testing Checklist for Human

  • Verify behavioral change is correct: The macro now extracts owner from tested_model_node only, not from all test_model_nodes. Confirm this matches the intended CORE-196 behavior.
  • Check relationship test coverage: The relationship tests are skipped on dbt fusion and dremio. Verify this is acceptable and that latest_official coverage is sufficient.
  • Manual verification: Run a relationship test between two models with different owners and verify only the primary model's owner appears in dbt_tests.model_owners.

Notes

Summary by CodeRabbit

  • Refactor

    • Test ownership is now attributed from the primary (tested) model instead of being extracted per-test node.
    • Owner deduplication now occurs after collecting owners from both tests and primary models, which can change owner lists in artifacts.
    • Tag deduplication behavior is unchanged.
  • Tests

    • New integration tests verify owner attribution, relationship-test owner selection, empty-owner handling, and owner deduplication.

✏️ Tip: You can customize this high-level summary in your review settings.

Previously, the flatten_test macro collected owners from ALL parent models
that a test references. This was incorrect for multi-parent tests like
relationship tests, where only the primary model's owner should be attributed.

Changes:
- Remove owner collection from the parent models loop
- Add owner extraction from the primary model inside the tested_model_node block
- Keep tag collection from all parent models unchanged

This ensures that:
- Single parent tests: Owner attribution unchanged (backward compatible)
- Multi-parent tests: Only primary model's owner shown
- Relationship tests: Only the 'tested' model's owner attributed
- Override scenarios: Respect override_primary_test_model_id configuration

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@linear
Copy link

linear bot commented Dec 16, 2025

@github-actions
Copy link
Contributor

👋 @devin-ai-integration[bot]
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

Owner collection for dbt tests now extracts owners only from the primary/tested model node (determined by primary_test_model_id) rather than from every referenced parent model. Tag aggregation from parent models is unchanged. Owner deduplication runs after all owner sources are gathered. New integration tests validate this behavior.

Changes

Cohort / File(s) Change Summary
Macro: test owner attribution
macros/edr/dbt_artifacts/upload_dbt_tests.sql
Removed owner extraction from the loop over all referenced parent/test_model nodes. Added owner extraction from the selected primary/tested model node (primary_model_owner from tested_model_node) after primary model selection. Moved deduplication of test_models_owners to run after all owners are collected. Tag aggregation from parent models is unchanged.
Integration tests: owners behavior
integration_tests/tests/test_dbt_artifacts/test_test_owners.py
Added new integration test module with helpers (cleanup_file, _parse_model_owners, _create_model_sql) and tests: test_single_parent_test_owner_attribution, test_relationship_test_uses_primary_model_owner_only, test_relationship_test_no_owner_on_primary_model, and test_owner_deduplication. Tests cover single-parent, relationship, missing-owner, and deduplication scenarios.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing test owner extraction to use only the primary model instead of all referenced models.
Linked Issues check ✅ Passed All objectives from CORE-196 are met: owner collection removed from parent loop, extraction moved to primary model block, deduplication preserved, and comprehensive tests validate single-parent, relationship, and edge cases.
Out of Scope Changes check ✅ Passed All changes are directly related to CORE-196: modifications to upload_dbt_tests.sql and new integration tests in test_test_owners.py focus on correcting test ownership attribution without introducing unrelated changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch core-196-1765897951-fix-test-ownership

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8d91cf6 and 70cbe55.

📒 Files selected for processing (1)
  • macros/edr/dbt_artifacts/upload_dbt_tests.sql (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: GuyEshdat
Repo: elementary-data/dbt-data-reliability PR: 838
File: integration_tests/tests/dbt_project.py:191-201
Timestamp: 2025-08-10T11:29:19.004Z
Learning: In the Elementary dbt package integration tests, BigQuery works correctly with the default `("database", "schema")` property mapping in the `get_database_and_schema_properties` function. When using `target.database` and `target.schema` in source definitions, BigQuery's dbt adapter handles these references appropriately without requiring special mapping to `project` and `dataset`.
📚 Learning: 2025-09-04T09:14:40.621Z
Learnt from: haritamar
Repo: elementary-data/dbt-data-reliability PR: 825
File: macros/edr/tests/test_dimension_anomalies.sql:73-75
Timestamp: 2025-09-04T09:14:40.621Z
Learning: In the dbt-data-reliability codebase, `flatten_model` is a valid macro defined in `macros/edr/dbt_artifacts/upload_dbt_models.sql` and can be used as a parameter to `elementary.get_anomaly_query()` even though other test files use the `flattened_test` variable instead.

Applied to files:

  • macros/edr/dbt_artifacts/upload_dbt_tests.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, clickhouse) / test
🔇 Additional comments (1)
macros/edr/dbt_artifacts/upload_dbt_tests.sql (1)

84-91: LGTM – Tag collection preserved, owner collection correctly removed.

The loop now only collects tags from all parent models, which aligns with the PR objective. Owner collection has been appropriately removed from this section and moved to the primary model extraction block.

devin-ai-integration bot and others added 2 commits December 17, 2025 06:54
Address CodeRabbit review comment: restore the unique filter for
test_models_owners to ensure no duplicate owners appear in model_owners,
maintaining backward compatibility with the original behavior.

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (5)

44-44: Remove unused tmp_path parameter.

The tmp_path fixture is declared but unused in this test function. The test uses dbt_project.models_dir_path for file operations instead.

-def test_single_parent_test_owner_attribution(dbt_project: DbtProject, tmp_path):
+def test_single_parent_test_owner_attribution(dbt_project: DbtProject):

100-102: Remove unused tmp_path parameter.

Same issue as the previous test—tmp_path is unused.

 def test_relationship_test_uses_primary_model_owner_only(
-    dbt_project: DbtProject, tmp_path
+    dbt_project: DbtProject,
 ):

192-192: Remove unused tmp_path parameter.

-def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject, tmp_path):
+def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject):

275-275: Remove unused tmp_path parameter.

-def test_owner_deduplication(dbt_project: DbtProject, tmp_path):
+def test_owner_deduplication(dbt_project: DbtProject):

320-328: Consider simplifying with set comparison.

The current assertions work correctly but could be consolidated using set comparison for clarity:

-            assert (
-                len(model_owners) == 2
-            ), f"Expected 2 unique owners, got {len(model_owners)}: {model_owners}"
-            assert (
-                "Alice" in model_owners
-            ), f"Expected 'Alice' in model_owners, got {model_owners}"
-            assert (
-                "Bob" in model_owners
-            ), f"Expected 'Bob' in model_owners, got {model_owners}"
+            assert set(model_owners) == {
+                "Alice",
+                "Bob",
+            }, f"Expected {{'Alice', 'Bob'}}, got {model_owners}"
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between dd3b9fe and 034dee9.

📒 Files selected for processing (1)
  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: GuyEshdat
Repo: elementary-data/dbt-data-reliability PR: 838
File: integration_tests/tests/dbt_project.py:191-201
Timestamp: 2025-08-10T11:29:19.004Z
Learning: In the Elementary dbt package integration tests, BigQuery works correctly with the default `("database", "schema")` property mapping in the `get_database_and_schema_properties` function. When using `target.database` and `target.schema` in source definitions, BigQuery's dbt adapter handles these references appropriately without requiring special mapping to `project` and `dataset`.
🧬 Code graph analysis (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)
integration_tests/tests/conftest.py (1)
  • dbt_project (144-147)
integration_tests/tests/dbt_project.py (3)
  • DbtProject (46-334)
  • write_yaml (325-334)
  • read_table (89-107)
🪛 Ruff (0.14.8)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py

44-44: Unused function argument: tmp_path

(ARG001)


101-101: Unused function argument: tmp_path

(ARG001)


192-192: Unused function argument: tmp_path

(ARG001)


275-275: Unused function argument: tmp_path

(ARG001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (latest_official, bigquery) / test
🔇 Additional comments (5)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (5)

14-21: LGTM!

The cleanup_file context manager correctly ensures file cleanup after the test block completes, even if an exception occurs.


24-41: LGTM!

The helper robustly handles the various formats that model_owners might be stored as across different database adapters (JSON string, native list, None).


49-97: LGTM!

Solid baseline test that verifies single-parent test owner attribution. Good use of unique identifiers to prevent test collisions and clear assertion messages.


103-189: LGTM!

This is the key test for CORE-196. It correctly validates that relationship tests only inherit the owner from the primary model ("Alice"), not from the referenced model ("Bob"). The assertion message is particularly helpful in explaining the expected behavior.


193-273: LGTM!

Important edge case that validates the primary model's owner is used—when the primary model has no owner, the result should be empty rather than inheriting from the referenced model.

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (5)

24-41: Consider clarifying line 38 behavior for non-list JSON.

The function correctly handles the expected formats (None, list, JSON array string). However, if JSON parsing succeeds but yields a non-list (e.g., {"key": "value"}), line 38 returns [model_owners_value] (the original string) rather than handling the parsed value explicitly. While this defensive behavior is acceptable for a test helper, you might consider making this edge case more explicit:

        try:
            parsed = json.loads(model_owners_value)
-           return parsed if isinstance(parsed, list) else [model_owners_value]
+           if isinstance(parsed, list):
+               return parsed
+           # Unexpected JSON structure; treat as single owner string
+           return [model_owners_value]
        except json.JSONDecodeError:

This makes the fallback intent clearer without changing behavior.


44-96: Remove unused tmp_path parameter.

The test logic correctly validates single-parent owner attribution. However, the tmp_path parameter is declared but never used.

Apply this diff:

-def test_single_parent_test_owner_attribution(dbt_project: DbtProject, tmp_path):
+def test_single_parent_test_owner_attribution(dbt_project: DbtProject):

Otherwise, the test is well-structured with clear assertions and proper cleanup.


99-191: Remove unused tmp_path parameter.

This is the key test for CORE-196 and correctly validates that relationship tests use only the primary model's owner. The test setup, assertion, and error messages clearly demonstrate the expected behavior.

Apply this diff:

 @pytest.mark.skip_targets(["dremio"])
 def test_relationship_test_uses_primary_model_owner_only(
-    dbt_project: DbtProject, tmp_path
+    dbt_project: DbtProject
 ):

193-277: Remove unused tmp_path parameter.

This test correctly validates the edge case where the primary model has no owner and ensures that the referenced model's owner is not inherited. This is important coverage for the CORE-196 requirements.

Apply this diff:

 @pytest.mark.skip_targets(["dremio"])
-def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject, tmp_path):
+def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject):

279-332: Remove unused tmp_path parameter.

This test correctly validates owner deduplication from comma-separated owner strings. The assertions appropriately check both the count and membership without assuming a specific order.

Apply this diff:

-def test_owner_deduplication(dbt_project: DbtProject, tmp_path):
+def test_owner_deduplication(dbt_project: DbtProject):
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 034dee9 and 9f1685a.

📒 Files selected for processing (1)
  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: GuyEshdat
Repo: elementary-data/dbt-data-reliability PR: 838
File: integration_tests/tests/dbt_project.py:191-201
Timestamp: 2025-08-10T11:29:19.004Z
Learning: In the Elementary dbt package integration tests, BigQuery works correctly with the default `("database", "schema")` property mapping in the `get_database_and_schema_properties` function. When using `target.database` and `target.schema` in source definitions, BigQuery's dbt adapter handles these references appropriately without requiring special mapping to `project` and `dataset`.
🧬 Code graph analysis (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)
integration_tests/tests/conftest.py (1)
  • dbt_project (144-147)
integration_tests/tests/dbt_project.py (3)
  • DbtProject (46-334)
  • write_yaml (325-334)
  • read_table (89-107)
🪛 Ruff (0.14.8)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py

44-44: Unused function argument: tmp_path

(ARG001)


101-101: Unused function argument: tmp_path

(ARG001)


194-194: Unused function argument: tmp_path

(ARG001)


279-279: Unused function argument: tmp_path

(ARG001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, dremio) / test
🔇 Additional comments (2)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)

1-12: LGTM! Clear module documentation and appropriate imports.

The docstring provides excellent context for the test suite's purpose, and all imports are relevant to the test implementation.


14-21: LGTM! Clean context manager pattern.

The cleanup_file helper correctly ensures test files are removed after each test, complementing the existing write_yaml cleanup for SQL model files.

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (4)

44-97: Remove unused parameter.

The tmp_path parameter is declared but never used in the function body. The test uses dbt_project.models_dir_path directly instead.

Apply this diff:

-def test_single_parent_test_owner_attribution(dbt_project: DbtProject, tmp_path):
+def test_single_parent_test_owner_attribution(dbt_project: DbtProject):

99-204: Excellent test coverage for the core requirement.

This test correctly validates the key CORE-196 behavior: relationship tests between models with different owners should only include the primary model's owner, not the referenced model's owner. The defensive filtering logic (lines 187-193) appropriately handles variations across dbt versions.

However, the tmp_path parameter is unused.

Apply this diff to remove the unused parameter:

 @pytest.mark.skip_targets(["dremio"])
 def test_relationship_test_uses_primary_model_owner_only(
-    dbt_project: DbtProject, tmp_path
+    dbt_project: DbtProject
 ):

206-303: Good edge case coverage.

This test correctly validates that when the primary model has no owner, the test should have empty model_owners even when the referenced model has an owner. This ensures referenced model owners are never inherited.

However, the tmp_path parameter is unused.

Apply this diff to remove the unused parameter:

 @pytest.mark.skip_targets(["dremio"])
-def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject, tmp_path):
+def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject):

305-358: Effective deduplication test.

This test validates that duplicate owners in comma-separated values are properly deduplicated. The assertion logic correctly verifies exactly 2 unique owners are present.

However, the tmp_path parameter is unused.

Apply this diff to remove the unused parameter:

-def test_owner_deduplication(dbt_project: DbtProject, tmp_path):
+def test_owner_deduplication(dbt_project: DbtProject):
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9f1685a and 8ff68b6.

📒 Files selected for processing (1)
  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: GuyEshdat
Repo: elementary-data/dbt-data-reliability PR: 838
File: integration_tests/tests/dbt_project.py:191-201
Timestamp: 2025-08-10T11:29:19.004Z
Learning: In the Elementary dbt package integration tests, BigQuery works correctly with the default `("database", "schema")` property mapping in the `get_database_and_schema_properties` function. When using `target.database` and `target.schema` in source definitions, BigQuery's dbt adapter handles these references appropriately without requiring special mapping to `project` and `dataset`.
🧬 Code graph analysis (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)
integration_tests/tests/conftest.py (1)
  • dbt_project (144-147)
integration_tests/tests/dbt_project.py (3)
  • DbtProject (46-334)
  • write_yaml (325-334)
  • read_table (89-107)
🪛 Ruff (0.14.8)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py

44-44: Unused function argument: tmp_path

(ARG001)


101-101: Unused function argument: tmp_path

(ARG001)


207-207: Unused function argument: tmp_path

(ARG001)


305-305: Unused function argument: tmp_path

(ARG001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, bigquery) / test
🔇 Additional comments (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1)

1-22: LGTM: Clean module setup and helper.

The module docstring clearly states the purpose, imports are appropriate, and the cleanup_file context manager correctly handles file cleanup with proper existence checks.

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1)

24-42: Fix the JSON parsing logic.

When json.loads() successfully parses a non-list value (e.g., a JSON string "Alice"), line 38 returns [model_owners_value] (the original JSON-encoded string) instead of [parsed] (the decoded value). This causes JSON-encoded strings to retain their quotes.

Example:

  • Input: '"Alice"'
  • json.loads('"Alice"')'Alice'
  • Current: returns ['"Alice"'] (with quotes)
  • Expected: returns ['Alice'] (decoded)

Apply this diff:

         try:
             parsed = json.loads(model_owners_value)
-            return parsed if isinstance(parsed, list) else [model_owners_value]
+            return parsed if isinstance(parsed, list) else [parsed]
         except json.JSONDecodeError:
🧹 Nitpick comments (4)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (4)

44-97: Consider removing unused tmp_path parameter.

The tmp_path parameter is declared but never used in the function body. If it's not required by pytest fixtures, consider removing it.

Apply this diff if the parameter is not required:

-def test_single_parent_test_owner_attribution(dbt_project: DbtProject, tmp_path):
+def test_single_parent_test_owner_attribution(dbt_project: DbtProject):

99-195: Excellent validation of CORE-196, but consider removing unused parameter.

The test logic correctly validates that relationship tests only use the primary model's owner (Alice) and not the referenced model's owner (Bob). The explicit test name approach and clear assertion messages make this test robust.

However, the tmp_path parameter is unused.

Apply this diff to remove the unused parameter if not required:

 @pytest.mark.skip_targets(["dremio"])
 def test_relationship_test_uses_primary_model_owner_only(
-    dbt_project: DbtProject, tmp_path
+    dbt_project: DbtProject
 ):

197-285: Good edge case coverage, but consider removing unused parameter.

The test correctly validates that when the primary model has no owner, the test doesn't inherit from the referenced model (Bob). This edge case is important for CORE-196.

However, the tmp_path parameter is unused.

Apply this diff to remove the unused parameter if not required:

 @pytest.mark.skip_targets(["dremio"])
-def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject, tmp_path):
+def test_relationship_test_no_owner_on_primary_model(dbt_project: DbtProject):

287-340: Solid deduplication test, but consider removing unused parameter.

The test correctly validates that duplicate owners are deduplicated (Alice,Bob,Alice → 2 unique owners). The order-agnostic assertions are appropriate for this use case.

However, the tmp_path parameter is unused.

Apply this diff to remove the unused parameter if not required:

-def test_owner_deduplication(dbt_project: DbtProject, tmp_path):
+def test_owner_deduplication(dbt_project: DbtProject):
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8ff68b6 and dcc5a60.

📒 Files selected for processing (1)
  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-10T11:29:19.004Z
Learnt from: GuyEshdat
Repo: elementary-data/dbt-data-reliability PR: 838
File: integration_tests/tests/dbt_project.py:191-201
Timestamp: 2025-08-10T11:29:19.004Z
Learning: In the Elementary dbt package integration tests, BigQuery works correctly with the default `("database", "schema")` property mapping in the `get_database_and_schema_properties` function. When using `target.database` and `target.schema` in source definitions, BigQuery's dbt adapter handles these references appropriately without requiring special mapping to `project` and `dataset`.

Applied to files:

  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py
🧬 Code graph analysis (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)
integration_tests/tests/conftest.py (1)
  • dbt_project (144-147)
integration_tests/tests/dbt_project.py (3)
  • DbtProject (46-334)
  • write_yaml (325-334)
  • read_table (89-107)
🪛 Ruff (0.14.8)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py

44-44: Unused function argument: tmp_path

(ARG001)


101-101: Unused function argument: tmp_path

(ARG001)


198-198: Unused function argument: tmp_path

(ARG001)


287-287: Unused function argument: tmp_path

(ARG001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, snowflake) / test
🔇 Additional comments (2)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)

1-12: LGTM!

The module docstring clearly explains the purpose and references CORE-196, and all imports are appropriate for the integration tests.


14-22: LGTM!

The cleanup_file context manager is correctly implemented with proper try/finally pattern and existence check before unlinking.

- Fix JSON parsing logic in _parse_model_owners to return [parsed] instead of [model_owners_value] when json.loads succeeds with a non-list value
- Remove unused tmp_path parameter from all 4 test functions

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
@devin-ai-integration
Copy link
Contributor Author

Addressed the CodeRabbit review comments in commit 2b638fa:

  1. Fixed JSON parsing bug in _parse_model_owners: Changed return parsed if isinstance(parsed, list) else [model_owners_value] to return parsed if isinstance(parsed, list) else [parsed]. This ensures that when json.loads() successfully parses a non-list value (e.g., "Alice"), we return the decoded value rather than the original JSON-encoded string with quotes.

  2. Removed unused tmp_path parameter from all 4 test functions to fix the Ruff ARG001 warnings.

devin-ai-integration bot and others added 2 commits December 23, 2025 15:37
Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1)

48-66: LGTM! Consider escaping owner values.

The utility function successfully reduces duplication across tests. Type hints have been properly added.

One minor consideration: if an owner value ever contains single quotes (e.g., "Alice's Team"), the f-string interpolation at line 61 could produce invalid Jinja syntax. However, since this is a test utility with controlled inputs (current tests only use simple names like "Alice" and "Bob"), this is unlikely to be an issue in practice.

🔎 Optional: Add escaping for special characters

If you want to make the utility more robust against special characters, you could use json.dumps to safely escape the owner value:

+import json
+
 def _create_model_sql(owner: Optional[str] = None, columns: str = "1 as id") -> str:
     if owner is not None:
+        escaped_owner = json.dumps(owner)
         return f"""
-    {{{{ config(meta={{'owner': '{owner}'}}) }}}}
+    {{{{ config(meta={{'owner': {escaped_owner}}}) }}}}
     select {columns}
     """
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f675954 and 9784f83.

📒 Files selected for processing (1)
  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py
🧰 Additional context used
🧬 Code graph analysis (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (2)
integration_tests/tests/conftest.py (1)
  • dbt_project (144-147)
integration_tests/tests/dbt_project.py (3)
  • DbtProject (46-334)
  • write_yaml (325-334)
  • read_table (89-107)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, redshift) / test
🔇 Additional comments (7)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (7)

1-13: LGTM!

The imports and module docstring are clear and well-organized. The docstring effectively explains the purpose of these tests in relation to CORE-196.


16-23: LGTM!

The context manager is properly implemented with correct type hints and defensive checks before file deletion.


26-45: LGTM!

The JSON parsing logic is now correct. Line 42 properly returns [parsed] instead of [model_owners_value], ensuring that decoded values are used without JSON quotes. Type hints have been added as requested in past reviews.


69-114: LGTM!

This baseline test is well-structured and correctly validates that a single-parent test inherits the owner from its model. The test properly:

  • Uses unique identifiers to avoid conflicts
  • Cleans up resources with context managers
  • Provides clear assertion messages
  • Uses the _create_model_sql utility to reduce duplication

117-209: LGTM!

This is the key test validating CORE-196's core objective. The test correctly verifies that relationship tests only extract the owner from the primary model (Alice), not from the referenced model (Bob). Excellent practices:

  • Explicit test name for robust querying across dbt versions
  • Clear assertion message explaining expected behavior
  • Proper skip marker for dremio target
  • Comprehensive cleanup of resources

212-295: LGTM!

This test validates the important edge case where the primary model has no owner but the referenced model does. It correctly verifies that ownership is not inherited from the referenced model, confirming the "primary model only" behavior introduced by CORE-196.


298-348: LGTM!

This test correctly validates the deduplication behavior mentioned in the PR objectives. The test uses order-independent assertions (checking length and membership rather than exact list equality), which is a robust approach that won't break if the macro changes the order of deduplicated owners.

…differs)

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (1)

300-350: Verify comma-separated owner parsing behavior.

The test passes "Alice,Bob,Alice" as a single string to the owner parameter, which embeds it into the dbt config as meta={'owner': 'Alice,Bob,Alice'}. The test then expects this to be parsed into separate owners and deduplicated.

Please confirm that the dbt artifacts system is designed to split comma-separated values in the meta.owner field. This is non-standard for dbt meta fields, which typically use lists in YAML.

Optional: Consider set-based assertion for clarity

The current assertions check length and membership separately. A set-based assertion might be slightly clearer:

assert set(model_owners) == {"Alice", "Bob"}, \
    f"Expected unique owners {{'Alice', 'Bob'}}, got {set(model_owners)}"

This is optional—the current approach is perfectly valid and explicit.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9784f83 and b6a9b58.

📒 Files selected for processing (1)
  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (latest_official, clickhouse) / test
  • GitHub Check: test (latest_official, postgres) / test
🔇 Additional comments (4)
integration_tests/tests/test_dbt_artifacts/test_test_owners.py (4)

16-66: LGTM! Helper functions are well-implemented.

The helper functions properly address past review comments:

  • Type hints added to all function arguments and return types
  • _create_model_sql utility created to reduce code duplication
  • JSON parsing bug fixed (line 42 correctly returns [parsed])

The implementations are clean, well-documented, and handle edge cases appropriately.


69-114: LGTM! Single parent test is well-structured.

The test properly validates the baseline case where a test on a single model inherits the owner from that model. Good use of the _create_model_sql utility and proper cleanup handling.


117-210: LGTM! Core CORE-196 test validates primary model owner behavior.

This test correctly validates that relationship tests only use the owner from the primary model (the one being tested), not from referenced models. The explicit test naming strategy and detailed assertion messages make this test robust and maintainable.


213-297: LGTM! Edge case test validates no owner inheritance from referenced models.

This test properly validates that when the primary model has no owner, the test's model_owners remains empty even if the referenced model has an owner. This confirms owners don't leak from non-primary models.

@arbiv arbiv enabled auto-merge (squash) December 28, 2025 12:51
@arbiv arbiv merged commit cffd655 into master Dec 29, 2025
28 of 32 checks passed
@arbiv arbiv deleted the core-196-1765897951-fix-test-ownership branch December 29, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants