Skip to content

Commit 7433d99

Browse files
Fokkosungwy
authored andcommitted
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 846e6de commit 7433d99

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

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:
@@ -774,9 +775,15 @@ def commit_table(
774775
identifier = self._identifier_to_tuple_without_catalog(table.identifier)
775776
table_identifier = TableIdentifier(namespace=identifier[:-1], name=identifier[-1])
776777
table_request = CommitTableRequest(identifier=table_identifier, requirements=requirements, updates=updates)
778+
779+
headers = self._session.headers
780+
if table_token := table.config.get(TOKEN):
781+
headers[AUTHORIZATION_HEADER] = f"{BEARER_PREFIX} {table_token}"
782+
777783
response = self._session.post(
778784
self.url(Endpoints.update_table, prefixed=True, **self._split_identifier_for_path(table_request.identifier)),
779785
data=table_request.model_dump_json().encode(UTF8),
786+
headers=headers,
780787
)
781788
try:
782789
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)