Repository navigation
fix: robust XML request handling - #77
Merged
Merged
Conversation
- Return 400 "Invalid XML: ..." for malformed XML bodies instead of a 500 error - Parse the request body once instead of once per column - With format='xml', read query parameters when the request has no body (e.g. ESP32 POST /measure?temperature=21), as for other formats; this always failed with a 500 error before - Accept the password as a <password> element in an XML body, like the "password" field in a JSON body - Reject column names that are not valid XML element names when the XML format is used, with a clear error at startup instead of a 500 error on the first measurement - Return 400 for a JSON body that is not an object (e.g. a list), instead of storing an empty row - Document how to send query, JSON and XML data; list xml in the SucculentAPI docstring; update the dependency tables in the docs (xmltodict is not used) - Add tests for all of the above Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VCvw8haRnmyrVKrLkz5Yf8
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.
Problems
Requests for the
xmlformat had several issues:Invalid XML: ...format='xml', no body, values in query string (ESP32 style, e.g.POST /measure?temperature=20)<password>element in an XML bodypasswordfieldmy temp)ValueErrorat startup[1, 2])Invalid JSON: ...The XML body was also parsed again for every column.
Changes
Processing.request_values()parses the request once (JSON object, XML body for thexmlformat, or query parameters) and is used byprocess().Processing.xml_values()parses an XML body and turnsParseErrorinto aValueError(400).request_passwords()also reads<password>from an XML body. The password is still checked before the body is used, and it is not stored.Processing.valid_xml_name()validates column names for thexmlformat at startup.req.json,req.data,req.args.get), so the existing mock-based tests pass unmodified.Docs
<password>element, and the column name rule for XML.SucculentAPIdocstring listsxml.docs/installation.rstupdated to matchpyproject.toml(xmltodictwas listed but is not used).Tests
TestXmlRequests(malformed XML, query string without body, body without content type,<password>element, JSON body with the XML format, column names) andTestJsonRequests(non-object JSON bodies). 12 of them fail on the previous code.Compatibility
Valid requests behave as before. Only requests that previously failed with a 500 error, or stored an empty row from a non-object JSON body, behave differently.
Generated by Claude Code