Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] multiple nested complex types expecting "any" and receiving etree._Element input #1384

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 5 additions & 3 deletions src/zeep/xsd/elements/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,20 @@ def render(self, parent, value, render_path):

self.validate(values, render_path)

child_path = render_path
for value in max_occurs_iter(self.max_occurs, values):
for name, element in self.elements_nested:
if name:
if name in value:
element_value = value[name]
child_path = render_path + [name]
child_path += [name]
elif isinstance(value, etree._Element):
element_value = value
child_path += [name]
else:
element_value = NotSet
child_path = render_path
else:
element_value = value
child_path = render_path

if element_value is SkipValue:
continue
Expand Down
39 changes: 39 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,45 @@ def test_nested_complex_types():
assert result["item"]["item_1"] == "foo"


def test_nested_complex_types_with_etree_input():
custom_type = xsd.Element(
etree.QName("http://tests.python-zeep.org/", "authentication"),
xsd.ComplexType(xsd.Sequence([
xsd.Element(
etree.QName("http://tests.python-zeep.org/", "data"),
xsd.ComplexType(xsd.Sequence([xsd.Any()])),
)
])),
)

root = etree.Element("values")
etree.SubElement(root, "item_1").text = "foo"
etree.SubElement(root, "item_2").text = "bar"

obj = custom_type(root)

expected = load_xml(
"""
<document>
<ns0:authentication xmlns:ns0="http://tests.python-zeep.org/">
<ns0:data>
<values>
<item_1>foo</item_1>
<item_2>bar</item_2>
</values>
</ns0:data>
</ns0:authentication>
</document>
"""
)
result = render_node(custom_type, obj)
assert_nodes_equal(result, expected)

obj = custom_type.parse(result[0], schema=xsd.Schema())
result = serialize_object(obj)
assert result == {"data": {"_value_1": root}}


def test_serialize_any_array():
custom_type = xsd.Element(
etree.QName("http://tests.python-zeep.org/", "authentication"),
Expand Down