Repository navigation
Conversation
…uest data The Android and iOS client SDKs send 64-bit integers in callable request data as typed proto3 wrappers. on_call passed them through as dicts, so a handler doing arithmetic on such a value failed with a 500. Decode the wrappers to int, as the Node.js SDK decodes them, and leave maps with any other @type unchanged.
There was a problem hiding this comment.
Code Review
This pull request introduces decoding logic for wrapped 64-bit integers (Int64Value and UInt64Value) sent by client SDKs in callable HTTPS functions, converting them into native Python integers. It also includes comprehensive unit tests for this behavior. The review feedback suggests optimizing performance by using Flask's cached request.get_json() instead of redundantly parsing the raw request data with _json.loads(request.data).
| context: CallableRequest = CallableRequest( | ||
| raw_request=request, | ||
| data=_json.loads(request.data)["data"], | ||
| data=_decode(_json.loads(request.data)["data"]), |
There was a problem hiding this comment.
Flask parses and caches the JSON body of the request when request.get_json() is called (which already happens during validation in _util.valid_on_call_request). Using _json.loads(request.data) parses the raw request body string a second time, which is redundant and inefficient. We can directly use the cached parsed JSON via request.get_json().
| data=_decode(_json.loads(request.data)["data"]), | |
| data=_decode(request.get_json()["data"]), |
The callable protocol encodes 64-bit integers as typed proto3 wrappers, for example
{"@type": "type.googleapis.com/google.protobuf.Int64Value", "value": "42"}. The Android SDK sends every Kotlin/JavaLongthis way, and the iOS SDK sends everyNSNumberwhose type islong long, which includes every SwiftInt. The Node.js SDK runsdecode()onreq.body.dataand the handler receives a plain number.on_callin this SDK passes the request'sdatathrough unchanged, so the handler receives the wrapper dict instead.Example: an iOS app calls
functions.httpsCallable("add").call(["count": 42]). The request body is{"data": {"count": {"@type": "type.googleapis.com/google.protobuf.Int64Value", "value": "42"}}}. A handler doingreq.data["count"] + 1raisesTypeError, and the client gets a 500INTERNALerror. The same handler returns 43 when the client sends a plain42.This change adds a small recursive
_decode()that_on_call_handlerapplies todata:Int64ValueandUInt64Valuewrappers become Pythonint. Usingintinstead offloat, which is what Node gets fromparseFloat, keeps values above 2^53 exact, matching how the Android and iOS SDKs decode these wrappers.@typestay as maps, as the callable protocol reference specifies ("If a map with an unknown@typefield is deserialized, it is left as a map"). Node throws in this case. Not throwing means data that works today keeps working.valueis not an integer string returns 400INVALID_ARGUMENTinstead of an unhandled 500.on_task_dispatchedis unchanged. The Node SDK decodes task payloads too, but I have no case where a task enqueuer sends these wrappers.Before and after, using a Flask test request against
on_call:{"count": 42}: 200 / 43 before, 200 / 43 after{"count": <Int64Value "42">}: 500 INTERNAL before, 200 / 43 after{"count": <Int64Value "9007199254740993">}: 500 INTERNAL before, 200 / 9007199254740994 afterTesting: added
test_on_call_decodes_wrapped_longstotests/test_https_fn.py. Without the fix it fails (4 failures, including 500 != 200). With the fix it passes, and the full suite passes (175 passed, macOS arm64, Python 3.11).ruff check,ruff format --checkandmypyare clean.This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.