dhkim1920 commented on code in PR #73783:
URL: https://github.com/apache/airflow/pull/73783#discussion_r4325415483
##########
task-sdk/src/airflow/sdk/execution_time/comms.py:
##########
@@ -176,14 +180,44 @@ def _new_encoder() -> msgspec.msgpack.Encoder:
return msgspec.msgpack.Encoder(enc_hook=_msgpack_enc_hook)
+def _encode_large_ints(value: Any) -> Any:
+ if isinstance(value, int) and not -(2**63) <= value < 2**64:
+ return msgspec.msgpack.Ext(
+ MP_HUGEINT, value.to_bytes((value.bit_length() + 8) // 8, "big",
signed=True)
+ )
+ if isinstance(value, dict):
+ return {key: _encode_large_ints(item) for key, item in value.items()}
+ if isinstance(value, (list, tuple)):
+ return [_encode_large_ints(item) for item in value]
+ if isinstance(value, msgspec.Struct):
+ return msgspec.structs.replace(
+ value, **{name: _encode_large_ints(getattr(value, name)) for name
in value.__struct_fields__}
+ )
+ if isinstance(value, BaseModel):
+ return _encode_large_ints(value.model_dump(exclude_unset=True))
+ return value
+
+
+def _decode_msgpack_ext(code: int, data: memoryview) -> Any:
+ if code == MP_HUGEINT:
+ return int.from_bytes(data, "big", signed=True)
+ return msgspec.msgpack.Ext(code, data)
+
+
class _FrameMixin:
_encoder: ClassVar[msgspec.msgpack.Encoder] = _new_encoder()
- def as_bytes(self) -> bytearray:
+ def as_bytes(self, *, allow_large_ints: bool = True) -> bytearray:
# https://jcristharif.com/msgspec/perf-tips.html#length-prefix-framing
for inspiration
buffer = bytearray(256)
- self._encoder.encode_into(self, buffer, 4) # type: ignore[arg-type]
+ try:
+ self._encoder.encode_into(self, buffer, 4) # type:
ignore[arg-type]
+ except OverflowError:
+ if not allow_large_ints:
Review Comment:
It is set to False for external language SDK subprocesses
(_PopenActivitySubprocess) and whenever _subprocess_schema_version is
explicitly set.
The MP_HUGEINT extension is currently implemented only for the unversioned
Python subprocess protocol. These guards prevent sending it to clients that may
not understand it. Normal integers are unaffected; oversized integers on those
channels retain the existing OverflowError behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]