Skip to content

Send typed wire values matching Python value's runtime type#142

Merged
zeevdr merged 1 commit into
mainfrom
fix/139-typed-value-write
Jun 8, 2026
Merged

Send typed wire values matching Python value's runtime type#142
zeevdr merged 1 commit into
mainfrom
fix/139-typed-value-write

Conversation

@zeevdr
Copy link
Copy Markdown
Member

@zeevdr zeevdr commented Jun 8, 2026

Summary

  • set()/set_many() always sent TypedValue(string_value=...), but the server requires the populated oneof variant to match the field's declared schema type exactly — every non-string field (bool, integer, number, time, duration, url, json) raised InvalidArgumentError.
  • make_typed_value() now picks the wire variant from the value's Python runtime type — bool/int/float/datetime/timedelta/dict/list/str map to bool_value/integer_value/number_value/time_value/duration_value/json_value/string_value respectively — mirroring convert_value() on the read side. No schema lookup or extra round trip needed.
  • URL becomes a real str subtype (was a plain alias) so url-typed fields, which also use a string wire representation but a distinct oneof variant, can be targeted by passing URL(...).

Test plan

  • Added test_stubs.py covering every make_typed_value branch (string, URL, bool-before-int ordering, integer, number, time, duration, json dict/list, unsupported type) — 100% coverage on _stubs.py
  • Added test_url_is_str_subtype confirming URL stays read-compatible with str while being distinguishable for writes
  • make lint / make typecheck / make test all pass (100% coverage)

Closes #139

set()/set_many() always wrapped the value in TypedValue(string_value=...),
but the server requires the populated oneof variant to match the field's
declared schema type exactly — so writing to any non-string field raised
InvalidArgumentError ("expected bool value", etc).

make_typed_value() now picks the wire variant from value's Python runtime
type (bool, int, float, datetime, timedelta, dict/list, str), mirroring
convert_value() on the read side — no schema lookup or extra round trip
needed. URL becomes a real str subtype so url-typed fields (which also use
a string wire representation, but a distinct oneof variant) can be targeted
by passing URL(...) instead of a plain str.

Closes #139
@zeevdr zeevdr added size: L Larger effort — multiple days, design decisions needed priority: P0 Blocks alpha or release labels Jun 8, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zeevdr zeevdr merged commit 0b12ee5 into main Jun 8, 2026
15 checks passed
@zeevdr zeevdr deleted the fix/139-typed-value-write branch June 8, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Blocks alpha or release size: L Larger effort — multiple days, design decisions needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client.set()/set_many() always send string_value, fail for non-string field types

1 participant