Skip to content

Commit 5313df8

Browse files
authored
Pass table-token to commit endpoint (apache#1278)
* 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 apache#1113 * Replace with constant
1 parent e771190 commit 5313df8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pyiceberg/catalog/rest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ def _response_to_table(self, identifier_tuple: Tuple[str, ...], table_response:
525525
{**table_response.metadata.properties, **table_response.config}, table_response.metadata_location
526526
),
527527
catalog=self,
528+
config=table_response.config,
528529
)
529530

530531
def _response_to_staged_table(self, identifier_tuple: Tuple[str, ...], table_response: TableResponse) -> StagedTable:
@@ -777,9 +778,15 @@ def commit_table(
777778
identifier = self._identifier_to_tuple_without_catalog(table.identifier)
778779
table_identifier = TableIdentifier(namespace=identifier[:-1], name=identifier[-1])
779780
table_request = CommitTableRequest(identifier=table_identifier, requirements=requirements, updates=updates)
781+
782+
headers = self._session.headers
783+
if table_token := table.config.get(TOKEN):
784+
headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {table_token}"
785+
780786
response = self._session.post(
781787
self.url(Endpoints.update_table, prefixed=True, **self._split_identifier_for_path(table_request.identifier)),
782788
data=table_request.model_dump_json().encode(UTF8),
789+
headers=headers,
783790
)
784791
try:
785792
response.raise_for_status()

pyiceberg/table/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,23 @@ class Table:
734734
metadata_location: str = Field()
735735
io: FileIO
736736
catalog: Catalog
737+
config: Dict[str, str]
737738

738739
def __init__(
739-
self, identifier: Identifier, metadata: TableMetadata, metadata_location: str, io: FileIO, catalog: Catalog
740+
self,
741+
identifier: Identifier,
742+
metadata: TableMetadata,
743+
metadata_location: str,
744+
io: FileIO,
745+
catalog: Catalog,
746+
config: Dict[str, str] = EMPTY_DICT,
740747
) -> None:
741748
self._identifier = identifier
742749
self.metadata = metadata
743750
self.metadata_location = metadata_location
744751
self.io = io
745752
self.catalog = catalog
753+
self.config = config
746754

747755
def transaction(self) -> Transaction:
748756
"""Create a new transaction object to first stage the changes, and then commit them to the catalog.

0 commit comments

Comments
 (0)