Skip to content

chore: improve cycle detection error#5338

Merged
eakmanrq merged 3 commits intomainfrom
eakmanrq/handle_indirect_cycles
Sep 10, 2025
Merged

chore: improve cycle detection error#5338
eakmanrq merged 3 commits intomainfrom
eakmanrq/handle_indirect_cycles

Conversation

@eakmanrq
Copy link
Collaborator

@eakmanrq eakmanrq commented Sep 9, 2025

Improve the cycle detection error message to output the exact cycle detected instead of potential candidates.

@eakmanrq eakmanrq force-pushed the eakmanrq/handle_indirect_cycles branch from a74d964 to 7600b10 Compare September 9, 2025 23:32
@eakmanrq eakmanrq requested a review from Copilot September 10, 2025 15:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR expands on a previous fix to handle indirect circular dependencies in DBT models by detecting cycles that are not created by direct dependencies. The fix improves error messages by providing exact cycle paths instead of candidate nodes.

  • Added a new DFS-based function to find exact cycle paths in graphs
  • Enhanced the DAG class to use precise cycle detection for better error messages
  • Extended DBT model handling to detect and resolve indirect circular references through test dependencies

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
sqlmesh/utils/dag.py Added find_path_with_dfs function for cycle detection and updated DAG error messages to show exact cycles
sqlmesh/dbt/basemodel.py Enhanced circular reference detection to handle indirect cycles and improved test movement logic
tests/utils/test_dag.py Updated test expectations to match new precise cycle error messages
tests/dbt/test_model.py Added comprehensive tests for indirect circular reference detection and resolution

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@eakmanrq eakmanrq force-pushed the eakmanrq/handle_indirect_cycles branch from c5b124f to 2d6bf20 Compare September 10, 2025 16:35
@eakmanrq eakmanrq changed the title fix: dbt handle indirect cycles chore: improve cycle detection error Sep 10, 2025
@eakmanrq eakmanrq force-pushed the eakmanrq/handle_indirect_cycles branch from 2d6bf20 to 93ce1e2 Compare September 10, 2025 16:37
cycle_msg = f"\nCycle: {' -> '.join(str(node) for node in cycle_path)} -> {cycle_path[0]}"
else:
last_processed_msg = ""
# Fallback message in case a cycle can't be found
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there scenarios where a cycle won't be found? I'm wondering if we can remove the else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No known scenarios at this time but it seems like a safe fallback to have in place for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to not have a fallback to get user feedback on what scenario hits it more quickly?

@eakmanrq eakmanrq merged commit 16a032f into main Sep 10, 2025
36 checks passed
@eakmanrq eakmanrq deleted the eakmanrq/handle_indirect_cycles branch September 10, 2025 18:23
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.

4 participants