Skip to content

Commit f3e94aa

Browse files
committed
fix: inline DynamoDB property prefix removal
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
1 parent 743e5fa commit f3e94aa

2 files changed

Lines changed: 4 additions & 25 deletions

File tree

pyiceberg/catalog/dynamodb.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,10 @@ def _get_update_database_item(namespace_item: dict[str, Any], updated_properties
837837

838838

839839
def _get_namespace_properties(namespace_dict: dict[str, str]) -> Properties:
840-
return {_remove_property_prefix(key): val for key, val in namespace_dict.items() if key.startswith(PROPERTY_KEY_PREFIX)}
840+
# removeprefix removes the literal prefix, unlike lstrip which removes any leading prefix characters
841+
return {
842+
key.removeprefix(PROPERTY_KEY_PREFIX): val for key, val in namespace_dict.items() if key.startswith(PROPERTY_KEY_PREFIX)
843+
}
841844

842845

843846
def _convert_dynamo_item_to_regular_dict(dynamo_json: dict[str, Any]) -> dict[str, str]:
@@ -888,7 +891,3 @@ def _convert_dynamo_item_to_regular_dict(dynamo_json: dict[str, Any]) -> dict[st
888891

889892
def _add_property_prefix(prop: str) -> str:
890893
return PROPERTY_KEY_PREFIX + prop
891-
892-
893-
def _remove_property_prefix(prop: str) -> str:
894-
return prop.removeprefix(PROPERTY_KEY_PREFIX)

tests/catalog/test_dynamodb.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -502,26 +502,6 @@ def test_load_namespace_properties(_bucket_initialize: None, database_name: str)
502502
assert v == test_properties[k]
503503

504504

505-
@mock_aws
506-
def test_load_namespace_properties_with_prefix_char_keys(_bucket_initialize: None, database_name: str) -> None:
507-
# Property keys starting with a character in the "p." prefix (e.g. "p" or ".") must
508-
# survive a round trip. The stored keys are prefixed with PROPERTY_KEY_PREFIX ("p."),
509-
# so decoding must strip only that literal prefix, not any leading "p"/"." characters.
510-
test_properties = {
511-
"provider": "s3",
512-
"path": f"s3://{BUCKET_NAME}/{database_name}.db",
513-
"ppp": "3",
514-
".hidden": "yes",
515-
"comment": "not affected",
516-
}
517-
test_catalog = DynamoDbCatalog("test_ddb_catalog")
518-
test_catalog.create_namespace(database_name, test_properties)
519-
listed_properties = test_catalog.load_namespace_properties(database_name)
520-
for k, v in test_properties.items():
521-
assert k in listed_properties
522-
assert listed_properties[k] == v
523-
524-
525505
@mock_aws
526506
def test_load_non_exist_namespace_properties(_bucket_initialize: None, database_name: str) -> None:
527507
test_catalog = DynamoDbCatalog("test_ddb_catalog")

0 commit comments

Comments
 (0)