From 235efa7f316065fc8ae6a0abe5c67fef2b8a6ac5 Mon Sep 17 00:00:00 2001 From: Vincent <1729065730@qq.com> Date: Thu, 29 Oct 2026 19:14:52 +0800 Subject: [PATCH] GH-35150: [Python] Make Flight value types pickleable Add __reduce__ for Action, Result, BasicAuth, FlightDescriptor, Ticket, Location, FlightEndpoint, SchemaResult, and FlightInfo so they round-trip through pickle (via existing serialize/deserialize, or URI for Location). --- python/pyarrow/_flight.pyx | 28 +++++++++++++ python/pyarrow/tests/test_flight.py | 62 +++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/python/pyarrow/_flight.pyx b/python/pyarrow/_flight.pyx index 2ab0ab618aec..b9a54483edd8 100644 --- a/python/pyarrow/_flight.pyx +++ b/python/pyarrow/_flight.pyx @@ -324,6 +324,9 @@ cdef class Action(_Weakrefable): CAction.Deserialize(tobytes(serialized))) return action + def __reduce__(self): + return Action.deserialize, (self.serialize(),) + def __eq__(self, Action other): return self.action == other.action @@ -391,6 +394,9 @@ cdef class Result(_Weakrefable): CFlightResult.Deserialize(tobytes(serialized))))) return result + def __reduce__(self): + return Result.deserialize, (self.serialize(),) + def __eq__(self, Result other): return deref(self.result.get()) == deref(other.result.get()) @@ -437,6 +443,9 @@ cdef class BasicAuth(_Weakrefable): def serialize(self): return GetResultValue(self.basic_auth.get().SerializeToString()) + def __reduce__(self): + return BasicAuth.deserialize, (self.serialize(),) + def __eq__(self, BasicAuth other): return deref(self.basic_auth.get()) == deref(other.basic_auth.get()) @@ -596,6 +605,9 @@ cdef class FlightDescriptor(_Weakrefable): CFlightDescriptor.Deserialize(tobytes(serialized))) return descriptor + def __reduce__(self): + return FlightDescriptor.deserialize, (self.serialize(),) + def __eq__(self, FlightDescriptor other): return self.descriptor == other.descriptor @@ -635,6 +647,9 @@ cdef class Ticket(_Weakrefable): CTicket.Deserialize(tobytes(serialized))) return ticket + def __reduce__(self): + return Ticket.deserialize, (self.serialize(),) + def __eq__(self, Ticket other): return self.c_ticket == other.c_ticket @@ -665,6 +680,10 @@ cdef class Location(_Weakrefable): return NotImplemented return self.location.Equals(( other).location) + def __reduce__(self): + # Location has no protobuf serialize helper; URI is sufficient. + return Location, (self.uri,) + @staticmethod def for_grpc_tcp(host, port): """Create a Location for a TCP-based gRPC service.""" @@ -829,6 +848,9 @@ cdef class FlightEndpoint(_Weakrefable): CFlightEndpoint.Deserialize(tobytes(serialized))) return endpoint + def __reduce__(self): + return FlightEndpoint.deserialize, (self.serialize(),) + def __repr__(self): return (f"