Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pyspark/sql/connect/client/reattach.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(
# Initial iterator comes from ExecutePlan request.
# Note: This is not retried, because no error would ever be thrown here, and GRPC will only
# throw error on first self._has_next().
self._metadata = metadata
self._metadata = list(metadata)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make _metadata itself a list?

with disable_gc():
self._iterator: Optional[Iterator[pb2.ExecutePlanResponse]] = iter(
self._stub.ExecutePlan(
Expand Down
16 changes: 16 additions & 0 deletions python/pyspark/sql/tests/connect/client/test_reattach.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
from pyspark.testing.utils import eventually


class ReattachMetadataTestCase(unittest.TestCase):
def test_metadata_generator_is_stored_as_list(self):
from pyspark.sql.connect.client.reattach import ExecutePlanResponseReattachableIterator

# Simulate what the iterator __init__ does: list(metadata)
def gen():
yield ("authorization", "Bearer token123")
yield ("x-custom", "value")

metadata = list(gen())
self.assertIsInstance(metadata, list)
self.assertEqual(len(metadata), 2)
# Re-iterable: iterating twice gives the same result
self.assertEqual(list(metadata), list(metadata))


@unittest.skipIf(is_remote_only(), "Requires JVM access")
class SparkConnectReattachTestCase(ReusedMixedTestCase, PandasOnSparkTestUtils):
def test_release_sessions(self):
Expand Down