Skip to content

fix: robust XML request handling - #77

Merged
firefly-cpp merged 1 commit into
mainfrom
fix/xml
Nov 8, 2026
Merged

firefly-cpp merged 1 commit into
mainfrom
fix/xml

Conversation

@firefly-cpp

Copy link
Copy Markdown
Owner

Problems

Requests for the xml format had several issues:

Request Before After
Malformed XML body 500 400 Invalid XML: ...
format='xml', no body, values in query string (ESP32 style, e.g. POST /measure?temperature=20) 500 (always) 200, values read from the query string like other formats
<password> element in an XML body ignored accepted, like the JSON password field
Column name that is not a valid XML element name (e.g. my temp) 500 on the first measurement clear ValueError at startup
JSON body that is not an object (e.g. [1, 2]) 200, stored an empty row 400 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 the xml format, or query parameters) and is used by process().
  • Processing.xml_values() parses an XML body and turns ParseError into a ValueError (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 the xml format at startup.
  • Request attributes used are unchanged (req.json, req.data, req.args.get), so the existing mock-based tests pass unmodified.

Docs

  • README and getting started: how to send data as query parameters, JSON or XML, the <password> element, and the column name rule for XML.
  • SucculentAPI docstring lists xml.
  • Dependency tables in docs/installation.rst updated to match pyproject.toml (xmltodict was listed but is not used).

Tests

  • New TestXmlRequests (malformed XML, query string without body, body without content type, <password> element, JSON body with the XML format, column names) and TestJsonRequests (non-object JSON bodies). 12 of them fail on the previous code.
  • Full suite: 37 passed.

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

- 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
@firefly-cpp
firefly-cpp merged commit 631bec7 into main Nov 8, 2026
12 checks passed
@firefly-cpp
firefly-cpp deleted the fix/xml branch November 8, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants