Skip to content

Commit 5de953a

Browse files
committed
fix attribute fetching logicalName handling
1 parent ca991c4 commit 5de953a

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

examples/basic/quickstart.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,18 @@ def run_paging_demo(label: str, *, top: Optional[int], page_size: Optional[int])
561561
created_details = column_create
562562
if not all(isinstance(item, str) for item in created_details):
563563
raise RuntimeError("create_column entries were not schema strings")
564-
attribute_schema = created_details[0]
564+
# create_columns returns logical names
565565
odata_client = client._get_odata()
566+
column_logical = created_details[0]
566567
exists_after_create = None
567568
exists_after_delete = None
568569
attr_type_before = None
569-
if metadata_id and attribute_schema:
570+
if metadata_id and column_logical:
570571
_ready_message = "Column metadata not yet available"
571572
def _metadata_after_create():
572573
meta = odata_client._get_attribute_metadata(
573574
metadata_id,
574-
attribute_schema,
575+
column_logical,
575576
extra_select="@odata.type,AttributeType",
576577
)
577578
if not meta or not meta.get("MetadataId"):
@@ -589,7 +590,8 @@ def _metadata_after_create():
589590
if isinstance(raw_type, str):
590591
attr_type_before = raw_type
591592
lowered = raw_type.lower()
592-
delete_target = attribute_schema or scratch_column
593+
# For delete, we pass the logical name
594+
delete_target = column_logical
593595
log_call(f"client.delete_column('{logical}', '{delete_target}')")
594596

595597
def _delete_column():
@@ -610,12 +612,14 @@ def _delete_column():
610612
deleted_details = column_delete
611613
if not all(isinstance(item, str) for item in deleted_details):
612614
raise RuntimeError("delete_column entries were not schema strings")
613-
if attribute_schema not in deleted_details:
615+
# deleted_details contains logical names (lowercase), so check for column_logical
616+
if column_logical not in deleted_details:
614617
raise RuntimeError("delete_column response missing expected schema name")
615-
if metadata_id and attribute_schema:
618+
if metadata_id and column_logical:
616619
_delete_message = "Column metadata still present after delete"
617620
def _ensure_removed():
618-
meta = odata_client._get_attribute_metadata(metadata_id, attribute_schema)
621+
# _get_attribute_metadata now accepts logical names
622+
meta = odata_client._get_attribute_metadata(metadata_id, column_logical)
619623
if meta:
620624
raise RuntimeError(_delete_message)
621625
return True

src/dataverse_sdk/data/odata.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,23 @@ def _create_entity(
881881
def _get_attribute_metadata(
882882
self,
883883
entity_metadata_id: str,
884-
schema_name: str,
884+
logical_name: str,
885885
extra_select: Optional[str] = None,
886886
) -> Optional[Dict[str, Any]]:
887-
attr_escaped = self._escape_odata_quotes(schema_name)
887+
"""Get attribute metadata by logical name.
888+
889+
Args:
890+
entity_metadata_id: The MetadataId of the entity
891+
logical_name: The logical name of the attribute (e.g., "new_category")
892+
extra_select: Optional comma-separated list of additional fields to select
893+
894+
Returns:
895+
Dict with attribute metadata, or None if not found
896+
"""
897+
# Normalize logical name for case-insensitive lookup
898+
logical_name = self._normalize_logical_name(logical_name)
899+
900+
attr_escaped = self._escape_odata_quotes(logical_name)
888901
url = f"{self.api}/EntityDefinitions({entity_metadata_id})/Attributes"
889902
select_fields = ["MetadataId", "LogicalName", "SchemaName"]
890903
if extra_select:
@@ -898,7 +911,7 @@ def _get_attribute_metadata(
898911
select_fields.append(piece)
899912
params = {
900913
"$select": ",".join(select_fields),
901-
"$filter": f"SchemaName eq '{attr_escaped}'",
914+
"$filter": f"LogicalName eq '{attr_escaped}'",
902915
}
903916
r = self._request("get", url, params=params)
904917
try:
@@ -1419,9 +1432,8 @@ def _delete_columns(
14191432
for column_name in names:
14201433
# Normalize column name for case-insensitive handling
14211434
column_name_normalized = self._normalize_logical_name(column_name)
1422-
# Look up actual SchemaName from server for existing attribute
1423-
col_schema = self._get_attribute_schema_name(logical_name, column_name_normalized)
1424-
attr_meta = self._get_attribute_metadata(metadata_id, col_schema, extra_select="@odata.type,AttributeType")
1435+
# Get attribute metadata by logical name
1436+
attr_meta = self._get_attribute_metadata(metadata_id, column_name_normalized, extra_select="@odata.type,AttributeType")
14251437
if not attr_meta:
14261438
raise MetadataError(
14271439
f"Column '{column_name}' not found on table '{logical_name}'.",

0 commit comments

Comments
 (0)