Skip to content

feat: define python client search attribute types#66

Open
timl3136 wants to merge 3 commits into
cadence-workflow:mainfrom
timl3136:search_attribute-1
Open

feat: define python client search attribute types#66
timl3136 wants to merge 3 commits into
cadence-workflow:mainfrom
timl3136:search_attribute-1

Conversation

@timl3136

@timl3136 timl3136 commented Feb 5, 2026

Copy link
Copy Markdown
Member

What changed?
defined the search attribute types in python client

Why?
in order to use search attribute in client, we need proper typing for search attributes.

How did you test it?
Unit test, it's not integrated with client yet.

Potential risks

Release notes

Documentation Changes

Signed-off-by: Tim Li <ltim@uber.com>
Signed-off-by: Tim Li <ltim@uber.com>
CADENCE_CHANGE_VERSION = "CadenceChangeVersion"


class SearchAttributeConverter:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't need this. My understanding is we only expose APIs like UpsertSearchAttributes. We can use python generics to get the type hints and thus use the dataconverter for actual convertion.

Comment on lines +76 to +78
for key, payload in attrs.indexed_fields.items():
hint = type_hints.get(key)
result[key] = self._decode_value(payload.data, hint)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: decode() lacks per-key error context unlike encode()

The encode() method wraps exceptions with the key name (encode search attribute [{key}] error: {e}), but decode() lets json.loads or datetime.fromisoformat exceptions propagate without indicating which key failed. When decoding corrupted or unexpected data from the server, users will get a raw JSONDecodeError or ValueError with no context about which attribute caused the failure.

Add per-key error wrapping in decode() consistent with encode():

for key, payload in attrs.indexed_fields.items():
    hint = type_hints.get(key)
    try:
        result[key] = self._decode_value(payload.data, hint)
    except (json.JSONDecodeError, ValueError) as e:
        raise ValueError(f"decode search attribute [{key}] error: {e}") from e
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented May 21, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Defines search attribute types with robust serialization and validation logic. Consider adding per-key error context to the decode() method to match the debugging detail provided in encode().

💡 Edge Case: decode() lacks per-key error context unlike encode()

📄 cadence/search_attributes.py:76-78

The encode() method wraps exceptions with the key name (encode search attribute [{key}] error: {e}), but decode() lets json.loads or datetime.fromisoformat exceptions propagate without indicating which key failed. When decoding corrupted or unexpected data from the server, users will get a raw JSONDecodeError or ValueError with no context about which attribute caused the failure.

Add per-key error wrapping in decode() consistent with encode()
for key, payload in attrs.indexed_fields.items():
    hint = type_hints.get(key)
    try:
        result[key] = self._decode_value(payload.data, hint)
    except (json.JSONDecodeError, ValueError) as e:
        raise ValueError(f"decode search attribute [{key}] error: {e}") from e
🤖 Prompt for agents
Code Review: Defines search attribute types with robust serialization and validation logic. Consider adding per-key error context to the `decode()` method to match the debugging detail provided in `encode()`.

1. 💡 Edge Case: decode() lacks per-key error context unlike encode()
   Files: cadence/search_attributes.py:76-78

   The `encode()` method wraps exceptions with the key name (`encode search attribute [{key}] error: {e}`), but `decode()` lets `json.loads` or `datetime.fromisoformat` exceptions propagate without indicating which key failed. When decoding corrupted or unexpected data from the server, users will get a raw `JSONDecodeError` or `ValueError` with no context about which attribute caused the failure.

   Fix (Add per-key error wrapping in decode() consistent with encode()):
   for key, payload in attrs.indexed_fields.items():
       hint = type_hints.get(key)
       try:
           result[key] = self._decode_value(payload.data, hint)
       except (json.JSONDecodeError, ValueError) as e:
           raise ValueError(f"decode search attribute [{key}] error: {e}") from e

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

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cadence/search_attributes.py 95.45% 2 Missing ⚠️
Files with missing lines Coverage Δ
cadence/__init__.py 100.00% <100.00%> (ø)
cadence/search_attributes.py 95.45% <95.45%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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