feat: define python client search attribute types#66
Conversation
Signed-off-by: Tim Li <ltim@uber.com>
| CADENCE_CHANGE_VERSION = "CadenceChangeVersion" | ||
|
|
||
|
|
||
| class SearchAttributeConverter: |
There was a problem hiding this comment.
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.
| for key, payload in attrs.indexed_fields.items(): | ||
| hint = type_hints.get(key) | ||
| result[key] = self._decode_value(payload.data, hint) |
There was a problem hiding this comment.
💡 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 👍 / 👎
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsDefines search attribute types with robust serialization and validation logic. Consider adding per-key error context to the 💡 Edge Case: decode() lacks per-key error context unlike encode()📄 cadence/search_attributes.py:76-78 The Add per-key error wrapping in decode() consistent with encode()🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
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