Skip to content

fix: Resolve ruff check failures in lfx deployment service#11992

Merged
ogabrielluiz merged 5 commits into
mainfrom
fix/ruff-checks
Mar 3, 2026
Merged

fix: Resolve ruff check failures in lfx deployment service#11992
ogabrielluiz merged 5 commits into
mainfrom
fix/ruff-checks

Conversation

@ogabrielluiz
Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz commented Mar 3, 2026

Summary

  • Split long default message string in DeploymentNotConfiguredError to stay within 120-char line limit (E501)
  • Changed ValueError to TypeError for isinstance checks in BaseFlowArtifact.validate_data (TRY004)
  • Added # noqa: ARG002 to intentionally unused stub method parameters in DeploymentService (ARG002)
  • Removed unnecessary parentheses on raised exceptions and suppressed PT012 for intentionally complex pytest.raises block in tests (RSE102, PT012)

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation error handling for deployment configuration checks.
  • New Features

    • Added a new teardown capability for deployment cleanup operations.

@ogabrielluiz ogabrielluiz requested a review from HzaRashid March 3, 2026 13:02
@github-actions github-actions Bot added the community Pull Request from an external contributor label Mar 3, 2026
@ogabrielluiz ogabrielluiz enabled auto-merge March 3, 2026 13:02
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This pull request updates the deployment service module with minor changes: a multi-line exception message string, exception type adjustments for validation errors, addition of type-checker suppression comments across method parameters, a new teardown method, and test syntax updates for exception raising.

Changes

Cohort / File(s) Summary
Exception and Validation Updates
src/lfx/src/lfx/services/deployment/exceptions.py, src/lfx/src/lfx/services/deployment/schema.py
String formatting change to exception message. Exception type changed from ValueError to TypeError when Flow 'nodes' or 'edges' validation fails type checks.
Service Method and Lint Updates
src/lfx/src/lfx/services/deployment/service.py
Added # noqa: ARG002 inline comments to all public method parameters in DeploymentService to suppress type-checker warnings. New public method teardown(self) -> None added that logs debug message.
Test Exception Handling
src/lfx/tests/unit/services/deployment/test_deployment_exceptions.py
Updated exception raising syntax within pytest.raises blocks from instance invocation to class reference (e.g., CredentialResolutionError() to CredentialResolutionError). Added # noqa: PT012 comment for lint suppression.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR adds new public teardown() method to DeploymentService without corresponding test coverage, and modifies error handling without verification. Add unit tests for the new teardown() method and verify TypeError change in schema.py works correctly with Pydantic v2.
Test Quality And Coverage ⚠️ Warning Test coverage is incomplete; validation error type change from ValueError to TypeError breaks Pydantic v2 semantics and is not caught by existing tests. Revert ValueError to TypeError changes in schema.py; add tests verifying ValidationError wrapping; enhance teardown test with logging verification and integration tests.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: resolving ruff linting check failures across the deployment service module.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
Test File Naming And Structure ✅ Passed The test file fully complies with custom check criteria, follows proper pytest structure with descriptive function names, includes comprehensive coverage of positive and negative scenarios with appropriate edge cases, uses clear docstrings, and the PR modifications appropriately improve code clarity.
Excessive Mock Usage Warning ✅ Passed Deployment service tests demonstrate excellent test design with minimal and appropriate mock usage, using real objects and 120+ assertions to verify actual implementation behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ruff-checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added the bug Something isn't working label Mar 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 23%
22.87% (7981/34889) 15.45% (4224/27334) 15.6% (1147/7348)

Unit Test Results

Tests Skipped Failures Errors Time
2611 0 💤 0 ❌ 0 🔥 45.443s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.31%. Comparing base (0cedf8a) to head (071f03f).
⚠️ Report is 3 commits behind head on main.

❌ Your project status has failed because the head coverage (42.29%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11992      +/-   ##
==========================================
- Coverage   37.33%   37.31%   -0.02%     
==========================================
  Files        1592     1592              
  Lines       78279    78279              
  Branches    11824    11824              
==========================================
- Hits        29226    29211      -15     
- Misses      47432    47448      +16     
+ Partials     1621     1620       -1     
Flag Coverage Δ
backend 57.32% <ø> (-0.08%) ⬇️
frontend 20.49% <ø> (ø)
lfx 42.29% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
src/lfx/src/lfx/services/deployment/exceptions.py 100.00% <ø> (ø)
src/lfx/src/lfx/services/deployment/schema.py 94.11% <100.00%> (ø)
src/lfx/src/lfx/services/deployment/service.py 100.00% <ø> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 3, 2026
Copy link
Copy Markdown
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lfx/src/lfx/services/deployment/schema.py`:
- Around line 60-63: Change the exceptions raised in the flow validation to
ValueError so Pydantic v2 wraps them into a ValidationError: in the field
validation block that checks value["nodes"] and value["edges"] (the validator
that raises "Flow 'nodes' must be a list" and "Flow 'edges' must be a list"),
replace the TypeError(...) raises with ValueError(...) so Pydantic will
aggregate these as validation errors rather than allowing TypeError to
propagate.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cedf8a and 62b2116.

📒 Files selected for processing (4)
  • src/lfx/src/lfx/services/deployment/exceptions.py
  • src/lfx/src/lfx/services/deployment/schema.py
  • src/lfx/src/lfx/services/deployment/service.py
  • src/lfx/tests/unit/services/deployment/test_deployment_exceptions.py

Comment on lines +60 to +63
raise TypeError(msg)
if not isinstance(value["edges"], list):
msg = "Flow 'edges' must be a list"
raise ValueError(msg)
raise TypeError(msg)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Pydantic v2 field_validator TypeError ValidationError conversion behavior

💡 Result:

In Pydantic v2, the key behavior change is:

  • Only “validation-style” exceptions raised inside validators—ValueError, AssertionError, or PydanticCustomError—are captured and aggregated into a ValidationError. (docs.pydantic.dev)
  • TypeError (and most other exceptions) raised inside a @field_validator is not converted into a ValidationError anymore; it bubbles up as the original TypeError. (docs.pydantic.dev)

What this means in practice

  • If your validator code accidentally triggers a TypeError (e.g., calling a function with the wrong types like str.lower(v) when v is an int, or using a wrong validator signature), your model construction/model_validate() will raise TypeError directly, not ValidationError. (docs.pydantic.dev)
  • If you want the error to appear as a field error inside a ValidationError, raise ValueError (or PydanticCustomError) instead of TypeError. (docs.pydantic.dev)

Citations:


Use ValueError instead of TypeError to preserve Pydantic validation semantics.

At Line 60 and Line 63, raising TypeError in a @field_validator bypasses Pydantic v2's ValidationError wrapping. In Pydantic v2, only ValueError, AssertionError, and PydanticCustomError are converted into a ValidationError; TypeError propagates directly, breaking normal error aggregation in request validation paths.

Proposed fix
         if not isinstance(value["nodes"], list):
             msg = "Flow 'nodes' must be a list"
-            raise TypeError(msg)
+            raise ValueError(msg)  # noqa: TRY004 - preserve ValidationError behavior
         if not isinstance(value["edges"], list):
             msg = "Flow 'edges' must be a list"
-            raise TypeError(msg)
+            raise ValueError(msg)  # noqa: TRY004 - preserve ValidationError behavior
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lfx/src/lfx/services/deployment/schema.py` around lines 60 - 63, Change
the exceptions raised in the flow validation to ValueError so Pydantic v2 wraps
them into a ValidationError: in the field validation block that checks
value["nodes"] and value["edges"] (the validator that raises "Flow 'nodes' must
be a list" and "Flow 'edges' must be a list"), replace the TypeError(...) raises
with ValueError(...) so Pydantic will aggregate these as validation errors
rather than allowing TypeError to propagate.

@ogabrielluiz ogabrielluiz removed the community Pull Request from an external contributor label Mar 3, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 3, 2026
@ogabrielluiz ogabrielluiz added this pull request to the merge queue Mar 3, 2026
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Mar 3, 2026
Merged via the queue into main with commit 5a18aaa Mar 3, 2026
96 of 97 checks passed
@ogabrielluiz ogabrielluiz deleted the fix/ruff-checks branch March 3, 2026 14:41
HimavarshaVS pushed a commit that referenced this pull request Mar 10, 2026
* fix: Improve message formatting in DeploymentNotConfiguredError

* fix: Change ValueError to TypeError for invalid flow nodes and edges

* fix: Add noqa comments to suppress ARG002 warnings for unused function arguments

* fix: Update exception raising in tests to improve clarity and suppress linting warnings

* fix: Change TypeError to ValueError so pydantic recognizes the error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants