From e7de0cceed6e7f4e68c427150b3d3bfd3625536d Mon Sep 17 00:00:00 2001 From: Fokko Date: Thu, 31 Oct 2024 22:09:57 +0100 Subject: [PATCH 1/2] Pass table-token to subsequent requests See open-api spec: https://github.com/apache/iceberg/blob/ea61ee46db17d94f22a5ef11fd913146557bdce7/open-api/rest-catalog-open-api.yaml#L927-L929 Resolves #1113 --- pyiceberg/catalog/rest.py | 7 +++++++ pyiceberg/table/__init__.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py index 20a04d9c5b..1275e9dbfa 100644 --- a/pyiceberg/catalog/rest.py +++ b/pyiceberg/catalog/rest.py @@ -525,6 +525,7 @@ def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response: {**table_response.metadata.properties, **table_response.config}, table_response.metadata_location ), catalog=self, + config=table_response.config, ) def _response_to_staged_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> StagedTable: @@ -777,9 +778,15 @@ def commit_table( identifier = self._identifier_to_tuple_without_catalog(table.identifier) table_identifier = TableIdentifier(namespace=identifier[:-1], name=identifier[-1]) table_request = CommitTableRequest(identifier=table_identifier, requirements=requirements, updates=updates) + + headers = self._session.headers + if table_token := table.config.get("token"): + headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {table_token}" + response = self._session.post( self.url(Endpoints.update_table, prefixed=True, **self._split_identifier_for_path(table_request.identifier)), data=table_request.model_dump_json().encode(UTF8), + headers=headers, ) try: response.raise_for_status() diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 264afd8971..18942948c0 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -784,15 +784,23 @@ class Table: metadata_location: str = Field() io: FileIO catalog: Catalog + config: Dict[str, str] def __init__( - self, identifier: Identifier, metadata: TableMetadata, metadata_location: str, io: FileIO, catalog: Catalog + self, + identifier: Identifier, + metadata: TableMetadata, + metadata_location: str, + io: FileIO, + catalog: Catalog, + config: Dict[str, str] = EMPTY_DICT, ) -> None: self._identifier = identifier self.metadata = metadata self.metadata_location = metadata_location self.io = io self.catalog = catalog + self.config = config def transaction(self) -> Transaction: """Create a new transaction object to first stage the changes, and then commit them to the catalog. From 9c1efbf94a7eea33f3bf6c2774746c753e20ebc6 Mon Sep 17 00:00:00 2001 From: Fokko Date: Mon, 4 Nov 2024 15:02:35 +0100 Subject: [PATCH 2/2] Replace with constant --- pyiceberg/catalog/rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py index 1275e9dbfa..7c5d774c27 100644 --- a/pyiceberg/catalog/rest.py +++ b/pyiceberg/catalog/rest.py @@ -780,7 +780,7 @@ def commit_table( table_request = CommitTableRequest(identifier=table_identifier, requirements=requirements, updates=updates) headers = self._session.headers - if table_token := table.config.get("token"): + if table_token := table.config.get(TOKEN): headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {table_token}" response = self._session.post(