📝 Improving XML processing in `XMLParser` for correct validation of Pydantic models (#541)
The current implementation of
XMLParser in django_test_app (and the example in the documentation) leads to massive validation errors (400 Bad Request) during automated testing via Schemathesis. The problem is caused by two factors:1. Extra nesting (Root Element):
xmltodict.parse always returns a dictionary where the data is nested in the key corresponding to the name of the root tag. Pydantic models (for example, _RequestModel) expects the data to be "flat", which is why validation crashes with the field required error for all fields, since they are wrapped in the tag name.2. Type mismatch for empty tags: XML does not have built-in types. Empty tags () are parsed by
xmltodict as None. If the Pydantic model expects str, it causes an error validation, although in the context of XML, an empty tag is often equivalent to an empty string.Most likely, this bug ( #499 ) is related to this, but the problem may be complex.
#enhancement #help_wanted #django_modern_rest
sent via relator