From dd3ffa9705afcbf93534fc44f5e7201b2b12aea7 Mon Sep 17 00:00:00 2001 From: Ayaan Date: Thu, 3 Dec 2026 12:15:37 +0530 Subject: [PATCH] GH-35288: [Python][FlightRPC] Accept str header keys and values in FlightCallOptions --- python/pyarrow/_flight.pyx | 3 ++- python/pyarrow/tests/test_flight.py | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/python/pyarrow/_flight.pyx b/python/pyarrow/_flight.pyx index b9a54483edd8..26e032d7f36f 100644 --- a/python/pyarrow/_flight.pyx +++ b/python/pyarrow/_flight.pyx @@ -131,7 +131,8 @@ cdef class FlightCallOptions(_Weakrefable): raise TypeError(f"expected IpcReadOptions, got {type(read_options)}") self.options.read_options = read_options.c_options if headers is not None: - self.options.headers = headers + self.options.headers = [(tobytes(key), tobytes(value)) + for key, value in headers] @staticmethod cdef CFlightCallOptions* unwrap(obj): diff --git a/python/pyarrow/tests/test_flight.py b/python/pyarrow/tests/test_flight.py index eb73e6d1778e..d59d9870f66d 100644 --- a/python/pyarrow/tests/test_flight.py +++ b/python/pyarrow/tests/test_flight.py @@ -1731,7 +1731,12 @@ def test_authenticate_basic_token_with_client_middleware(): client.close() -def test_arbitrary_headers_in_flight_call_options(): +# GH-35288 +@pytest.mark.parametrize("headers", [ + [('test-header-1', 'value1'), ('test-header-2', 'value2')], + [(b'test-header-1', b'value1'), (b'test-header-2', b'value2')], +]) +def test_arbitrary_headers_in_flight_call_options(headers): """Test passing multiple arbitrary headers to the middleware.""" with ArbitraryHeadersFlightServer( auth_handler=no_op_auth_handler, @@ -1743,11 +1748,7 @@ def test_arbitrary_headers_in_flight_call_options(): token_pair = client.authenticate_basic_token(b'test', b'password') assert token_pair[0] == b'authorization' assert token_pair[1] == b'Bearer token1234' - options = flight.FlightCallOptions(headers=[ - token_pair, - (b'test-header-1', b'value1'), - (b'test-header-2', b'value2') - ]) + options = flight.FlightCallOptions(headers=[token_pair, *headers]) result = list(client.do_action(flight.Action( "test-action", b""), options=options)) assert result[0].body.to_pybytes() == b'value1'