Fix xsd:import without namespace incorrectly inheriting parent targetNamespace#1488
Open
pauloxnet wants to merge 1 commit intomvantellingen:mainfrom
Open
Fix xsd:import without namespace incorrectly inheriting parent targetNamespace#1488pauloxnet wants to merge 1 commit intomvantellingen:mainfrom
pauloxnet wants to merge 1 commit intomvantellingen:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The block at lines 255-259 of
src/zeep/xsd/visitor.py(elif not schema_tns and not namespace: namespace = self.document._target_namespace) forces anxsd:import schemaLocation="..."without anamespaceattribute to inherit the importing schema'stargetNamespace. That isxsd:includesemantics, notxsd:importsemantics. The practical effect: elements declared in the imported no-namespace schema get re-registered under the parent namespace, and any unqualified QName referencing them (typicallywsdl:part element="Header"in asoap:headerbinding) fails to resolve, surfacing asIndexError: No definition '{tns}Header' in 'messages' found. WCF/.NET-generated WSDLs hit this routinely.The block was introduced in 713c779 ("Fix an issue with resolving qualified qname's used in references", #879, Dec 2018). One week later #888 / b7ad93e partially reverted the chameleon support and added the
_has_empty_importflag, but only for the<import/>case (no namespace, no location). At the time @mvantellingen noted "I'm wondering if that unittest is actually ok" and @apollo13 replied "Not sure if the test is wrong or the code needs more work". That uncertainty was never resolved. Issues #600 (Jan 2018) and #662 (Jun 2018) report the same symptom against WCF WSDLs and have stayed open or closed-without-fix since.Fix
Two changes in
visit_import:_has_empty_importis activated whenever an import omitsnamespace, per W3C XSD 4.1.2. The activation is placed at the three exit points so that an import naming a namespace incorrectly (which the existingXMLParseErrorrejects a few lines later) cannot poison the parent's QName resolution: on a cache hit, only when the cached document has no_target_namespace; on the canonical empty<import/>, in the missing-schemaLocationbranch; and post-load, only when the imported schema has notargetNamespaceeither.tests/test_wsdl.py::test_import_schema_without_namespace_and_headerreproduces the original failure (namespaced schema importing a no-namespace schema whose element is used as a SOAP header part) and asserts both that the element ends up under the null namespace and that no{tns}Headerghost registration exists.Breaking change
Strict W3C QName resolution has a real consequence. In a schema with
elementFormDefault="qualified"that does<xsd:import schemaLocation="..."/>(nonamespace) of a no-namespace schema, an unqualifiedrefto an element defined in the same importing schema now resolves in the null namespace and fails. The spec-compliant fix on the consumer side is the qualified form:This case is captured in
tests/test_xsd_schemas.py::test_no_target_namespace_unqualified_ref_to_own_element, markedxfail(strict=True)so any future change is a deliberate one. No existing test in the repository hits this pattern.