Skip to content

Commit 0f10a97

Browse files
yingjianwu98Yingjian Wu
andauthored
fix:update config during table refresh (#3327)
# Rationale for this change Table.refresh() was not updating self.config from the refreshed TableResponse. The config field contains out of date, server-generated properties such as per-table access tokens (token) and credential refresh endpoints(client.refresh-credentials-endpoint). ## Are these changes tested? Yes, with a new test. ## Are there any user-facing changes? No Co-authored-by: Yingjian Wu <yingjianw@netflix.com>
1 parent 6e68c9c commit 0f10a97

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

pyiceberg/table/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ def refresh(self) -> Table:
11031103
self.metadata = fresh.metadata
11041104
self.io = fresh.io
11051105
self.metadata_location = fresh.metadata_location
1106+
self.config = fresh.config
11061107
return self
11071108

11081109
def name(self) -> Identifier:

tests/catalog/test_rest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,39 @@ def test_table_uuid_check_on_commit(rest_mock: Mocker, example_table_metadata_v2
25352535
assert f"refreshed={different_uuid}" in str(exc_info.value)
25362536

25372537

2538+
def test_table_refresh_updates_config(rest_mock: Mocker, example_table_metadata_v2: dict[str, Any]) -> None:
2539+
metadata_location = "s3://warehouse/database/table/metadata.json"
2540+
2541+
rest_mock.get(
2542+
f"{TEST_URI}v1/namespaces/namespace/tables/table_name",
2543+
json={
2544+
"metadata-location": metadata_location,
2545+
"metadata": example_table_metadata_v2,
2546+
"config": {"original-key": "original-value"},
2547+
},
2548+
status_code=200,
2549+
request_headers=TEST_HEADERS,
2550+
)
2551+
2552+
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
2553+
table = catalog.load_table(("namespace", "table_name"))
2554+
assert table.config == {"original-key": "original-value"}
2555+
2556+
rest_mock.get(
2557+
f"{TEST_URI}v1/namespaces/namespace/tables/table_name",
2558+
json={
2559+
"metadata-location": metadata_location,
2560+
"metadata": example_table_metadata_v2,
2561+
"config": {"updated-key": "updated-value"},
2562+
},
2563+
status_code=200,
2564+
request_headers=TEST_HEADERS,
2565+
)
2566+
2567+
table.refresh()
2568+
assert table.config == {"updated-key": "updated-value"}
2569+
2570+
25382571
def test_table_uuid_check_on_refresh(rest_mock: Mocker, example_table_metadata_v2: dict[str, Any]) -> None:
25392572
original_uuid = "9c12d441-03fe-4693-9a96-a0705ddf69c1"
25402573
different_uuid = "550e8400-e29b-41d4-a716-446655440000"

0 commit comments

Comments
 (0)