Skip to content

fix: improve typings and remove mypy ignores#93

Merged
timl3136 merged 6 commits into
cadence-workflow:mainfrom
timl3136:error-fix
May 19, 2026
Merged

fix: improve typings and remove mypy ignores#93
timl3136 merged 6 commits into
cadence-workflow:mainfrom
timl3136:error-fix

Conversation

@timl3136
Copy link
Copy Markdown
Member

@timl3136 timl3136 commented Apr 23, 2026

What changed?
Improve typings and remove mypy ignores, also add clear mypy cache to make clean command

Why?
we should not use ignore to override type safety check.

How did you test it?
only typing improvements

Potential risks

Release notes

Documentation Changes


Summary by Gitar

  • Typing improvements:
    • Explicitly cast call_details.method to bytes in retry.py to handle runtime type changes in grpcio v1.75.0+.
    • Added cast in test suites to resolve type mismatches in GetWorkflowExecutionHistory responses and StartWorkflowOptions dictionary mocking.

This will update automatically on new commits.

Comment thread cadence/_internal/rpc/retry.py Outdated
Signed-off-by: Tim Li <ltim@uber.com>
timl3136 and others added 2 commits May 19, 2026 13:28
# Conflicts:
#	cadence/_internal/rpc/retry.py
#	cadence/_internal/rpc/yarpc.py
#	cadence/client.py
#	tests/cadence/_internal/rpc/test_error.py
#	tests/cadence/test_client_workflow.py
#	tests/integration_tests/workflow/test_retry_policy.py
@gitar-bot
Copy link
Copy Markdown

gitar-bot Bot commented May 19, 2026

Code Review 👍 Approved with suggestions 1 resolved / 2 findings

Expands the CadenceClient with comprehensive schedule and query workflow APIs while enforcing stricter type safety. The query decorator docstring requires an update to match the actual implementation.

💡 Quality: Query decorator docstring contradicts implementation

📄 cadence/workflow.py:391-400

The @workflow.query decorator docstring states "If not provided, use the function name" for the name parameter, but the implementation raises ValueError("name is required") when name is None. The docstring should be corrected to match the actual behavior (name is mandatory), or the implementation should fall back to f.__name__ like the docstring promises.

Fix docstring to match implementation (name is required)
Args:
    name: The name of the query type. Required.

Returns:
    The decorated method with workflow query metadata

Raises:
    ValueError: If name is not provided
"""
Alternative: fall back to function name when name is None, matching the docstring
if name is None:
    raise ValueError("name is required")

def decorator(f: T) -> T:
    query_name = name if name is not None else f.__name__
    f._workflow_query = query_name  # type: ignore[attr-defined]
    return f
✅ 1 resolved
Bug: is_retryable compares decoded str to bytes constant

📄 cadence/_internal/rpc/retry.py:47 📄 cadence/_internal/rpc/retry.py:105-109
At line 109 in retry.py, method has been decoded from bytes to str (line 106-107), but GET_WORKFLOW_HISTORY is defined as b"..." (bytes) on line 47. The comparison method == GET_WORKFLOW_HISTORY will always be False, breaking the retry-on-passive-side logic for GetWorkflowExecutionHistory. This means EntityNotExistsError from cross-cluster requests will no longer be retried.

If method is already a str (not bytes), the decode branch is skipped but the comparison still fails because the constant is bytes.

🤖 Prompt for agents
Code Review: Expands the CadenceClient with comprehensive schedule and query workflow APIs while enforcing stricter type safety. The query decorator docstring requires an update to match the actual implementation.

1. 💡 Quality: Query decorator docstring contradicts implementation
   Files: cadence/workflow.py:391-400

   The `@workflow.query` decorator docstring states "If not provided, use the function name" for the `name` parameter, but the implementation raises `ValueError("name is required")` when `name is None`. The docstring should be corrected to match the actual behavior (name is mandatory), or the implementation should fall back to `f.__name__` like the docstring promises.

   Fix (Fix docstring to match implementation (name is required)):
   Args:
       name: The name of the query type. Required.
   
   Returns:
       The decorated method with workflow query metadata
   
   Raises:
       ValueError: If name is not provided
   """

   Fix (Alternative: fall back to function name when name is None, matching the docstring):
   if name is None:
       raise ValueError("name is required")
   
   def decorator(f: T) -> T:
       query_name = name if name is not None else f.__name__
       f._workflow_query = query_name  # type: ignore[attr-defined]
       return f

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cadence/_internal/rpc/error.py 78.94% 4 Missing ⚠️
Files with missing lines Coverage Δ
cadence/_internal/rpc/retry.py 100.00% <100.00%> (+3.57%) ⬆️
cadence/_internal/rpc/yarpc.py 90.00% <100.00%> (ø)
cadence/client.py 86.50% <100.00%> (ø)
cadence/workflow.py 91.46% <100.00%> (ø)
cadence/_internal/rpc/error.py 90.58% <78.94%> (+0.11%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timl3136 timl3136 merged commit 245ca75 into cadence-workflow:main May 19, 2026
8 checks passed
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.

2 participants