Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
Preserve query XML singleton list wrappers (#1302)
Ian Oberst14d059848d15
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex f0e27348..297a2731 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -4514,12 +4514,13 @@ _XML_NUMERIC_FIELDS = frozenset({"MonitoringInterval", "PromotionTier", "DbInstancePort","MaxAllocatedStorage", "StorageThroughput",})-# Empty self-closing XML elements that should become [] not "".+# Known AWS query-protocol list wrappers. These remain lists for empty,+# singleton, and multi-item responses, including irregular wrapper/item names._XML_LIST_WRAPPER_TAGS = frozenset({"Parameters", "DBClusterMembers", "VpcSecurityGroups","AvailabilityZones", "Subnets", "ReadReplicaDBInstanceIdentifiers","ReadReplicaDBClusterIdentifiers", "DBSecurityGroups",- "OptionGroupMemberships", "StatusInfos", "DomainMemberships",+ "OptionGroupMemberships", "OptionGroupsList", "StatusInfos", "DomainMemberships","AssociatedRoles", "TagList", "ProcessorFeatures","EnabledCloudwatchLogsExports", "GlobalClusterMembers","DBParameterGroups", "DBInstances", "DBClusters", "Readers",@@ -4582,11 +4583,11 @@ def _xml_element_to_dict(element):return tag, text# Detect list-wrapper elements: all children share the same tag name AND- # the parent looks like a plural wrapper (e.g. DBClusters→DBCluster,- # AvailabilityZones→AvailabilityZone) or children use the generic- # "member" tag. We require either multiple children OR a plural naming- # pattern to avoid false positives on single-child result wrappers like- # <CreateDBClusterParameterGroupResult><DBClusterParameterGroup>...</>+ # the parent is a known wrapper, looks like a plural wrapper (e.g.+ # DBClusters→DBCluster, AvailabilityZones→AvailabilityZone), or children+ # use the generic "member" tag. Known wrappers cover AWS names whose item+ # tag cannot be inferred from the wrapper name (e.g.+ # VpcSecurityGroups→VpcSecurityGroupMembership).child_tags = {(c.tag.split("}")[-1] if "}" in c.tag else c.tag) for c in children}if len(child_tags) == 1:child_tag_name = next(iter(child_tags))@@ -4597,7 +4598,7 @@ def _xml_element_to_dict(element):or (tag.endswith("Ids") and child_tag_name == "Id"))has_multiple = len(children) > 1- if is_member or is_plural or has_multiple:+ if tag in _XML_LIST_WRAPPER_TAGS or is_member or is_plural or has_multiple:# Treat as a list.items = []for child in children:diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.pyindex cdc3f44f..a331e979 100644--- a/tests/test_stepfunctions.py+++ b/tests/test_stepfunctions.py@@ -4787,13 +4787,6 @@ def test_sfn_aws_sdk_query_acronym_param_mapping(sfn, sfn_sync, rds, ec2):"""SFN aws-sdk query dispatch maps SDK-style param names to wire-format names."""import uuid as _uuid- def normalize_vpc_security_groups(value):- # The converter currently collapses singleton wrappers to a dict; keep- # this assertion compatible with a future list-fidelity fix.- if isinstance(value, list):- return value- return [value["VpcSecurityGroupMembership"]]-cluster_id = f"acronym-test-{_uuid.uuid4().hex[:8]}"sm_name = f"sdk-acronym-{_uuid.uuid4().hex[:8]}"vpc_id = ec2.create_vpc(CidrBlock="10.98.0.0/16")["Vpc"]["VpcId"]@@ -4860,23 +4853,19 @@ def test_sfn_aws_sdk_query_acronym_param_mapping(sfn, sfn_sync, rds, ec2):create_cluster = output["createResult"]["DbCluster"]assert create_cluster["DbClusterIdentifier"] == cluster_idassert create_cluster["Engine"] == "aurora-postgresql"- assert normalize_vpc_security_groups(create_cluster["VpcSecurityGroups"]) == [+ assert create_cluster["VpcSecurityGroups"] == [{"VpcSecurityGroupId": create_sg_id,"Status": "active",},]- assert normalize_vpc_security_groups(- output["modifyResult"]["DbCluster"]["VpcSecurityGroups"],- ) == [+ assert output["modifyResult"]["DbCluster"]["VpcSecurityGroups"] == [{"VpcSecurityGroupId": modify_sg_id,"Status": "active",},]- assert normalize_vpc_security_groups(- output["describeResult"]["DbClusters"][0]["VpcSecurityGroups"],- ) == [+ assert output["describeResult"]["DbClusters"][0]["VpcSecurityGroups"] == [{"VpcSecurityGroupId": modify_sg_id,"Status": "active",@@ -4890,6 +4879,37 @@ def test_sfn_aws_sdk_query_acronym_param_mapping(sfn, sfn_sync, rds, ec2):ec2.delete_vpc(VpcId=vpc_id)[email protected](("wrapper_tag", "item_tag"), [+ ("VpcSecurityGroups", "VpcSecurityGroupMembership"),+ ("TagList", "Tag"),+ ("StatusInfos", "DBInstanceStatusInfo"),+ ("AssociatedRoles", "DBClusterRole"),+ ("OptionGroupsList", "OptionGroup"),+ ("ServerCertificateMetadataList", "ServerCertificateMetadata"),+])[email protected]("item_count", [0, 1, 2])+def test_sfn_query_xml_known_list_wrappers_preserve_list_shape(+ wrapper_tag,+ item_tag,+ item_count,+):+ """Known query-XML wrappers remain lists for empty, singleton, and multi values."""+ from xml.etree import ElementTree as ET++ from ministack.services.stepfunctions import _xml_element_to_dict++ items = "".join(+ f"<{item_tag}><Value>{index}</Value></{item_tag}>"+ for index in range(item_count)+ )+ root = ET.fromstring(f"<{wrapper_tag}>{items}</{wrapper_tag}>")++ tag, value = _xml_element_to_dict(root)++ assert tag == wrapper_tag+ assert value == [{"Value": str(index)} for index in range(item_count)]++def test_sfn_key_to_api_name_must_convert():"""Verify _sfn_key_to_api_name expands known acronyms to uppercase."""from ministack.services.stepfunctions import _sfn_key_to_api_name