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
5 changes: 2 additions & 3 deletions pyiceberg/catalog/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,9 +1170,8 @@ def _response_to_table(self, identifier_tuple: tuple[str, ...], table_response:

def _response_to_staged_table(self, identifier_tuple: tuple[str, ...], table_response: TableResponse) -> StagedTable:
# Per Iceberg spec: storage-credentials take precedence over config
credential_config = self._resolve_storage_credentials(
table_response.storage_credentials, table_response.metadata_location
)
credential_location = table_response.metadata_location or f"{table_response.metadata.location.rstrip('/')}/"
credential_config = self._resolve_storage_credentials(table_response.storage_credentials, credential_location)
return StagedTable(
identifier=identifier_tuple,
metadata_location=table_response.metadata_location, # type: ignore
Expand Down
27 changes: 27 additions & 0 deletions tests/catalog/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,33 @@ def test_create_staged_table_200(
assert actual_response == expected


def test_create_staged_table_with_storage_credentials(
rest_mock: Mocker,
table_schema_simple: Schema,
example_table_metadata_no_snapshot_v1: dict[str, Any],
) -> None:
table_location = "gs://bucket/ns/t"
rest_mock.post(
f"{TEST_URI}v1/namespaces/fokko/tables",
json={
"metadata": {**example_table_metadata_no_snapshot_v1, "location": table_location},
"config": {},
"storage-credentials": [
{
"prefix": f"{table_location}/",
"config": {"gcs.oauth2.token": "vended"},
}
],
},
status_code=200,
request_headers=TEST_HEADERS,
)
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
txn = catalog.create_table_transaction(identifier=("fokko", "fokko2"), schema=table_schema_simple)

assert txn._table.io.properties["gcs.oauth2.token"] == "vended"


def test_create_table_409(rest_mock: Mocker, table_schema_simple: Schema) -> None:
rest_mock.post(
f"{TEST_URI}v1/namespaces/fokko/tables",
Expand Down
Loading