Skip to content

fix: $resultFormat=CSV and GeoJSON crash server with 500, parser token missing#184

Open
Vishmayraj wants to merge 1 commit into
istSOS:mainfrom
Vishmayraj:fix/result-format-csv-geojson
Open

fix: $resultFormat=CSV and GeoJSON crash server with 500, parser token missing#184
Vishmayraj wants to merge 1 commit into
istSOS:mainfrom
Vishmayraj:fix/result-format-csv-geojson

Conversation

@Vishmayraj

@Vishmayraj Vishmayraj commented May 29, 2026

Copy link
Copy Markdown
Contributor

While working on the STA to STAC metadata connector, I needed to fetch observations in CSV format to test the pipeline. Every request with $resultFormat=CSV was returning 500, so I pulled the Docker logs and traced the error.

The root cause was in lexer.py where the RESULT_FORMAT_VALUE token pattern only matched dataArray. So when the parser saw CSV, it tokenized it as an EXPAND_IDENTIFIER and threw an exception. That exception had no dedicated handler in read.py, so it fell through to the generic except Exception block and returned 500.

Changes

lexer.py => extend the pattern to cover all three spec-defined values:

# before
"RESULT_FORMAT_VALUE": r"\bdataArray\b",
# after
"RESULT_FORMAT_VALUE": r"\bdataArray\b|\bCSV\b|\bGeoJSON\b",

read.py => wrap convert_query in its own try/except returning 400. Parser exceptions are always caused by malformed client input, not server faults, so 500 was the wrong code here regardless.

Note

While tracing this I found that CSV and GeoJSON serialization is not actually implemented. The parser scaffolding exists, ResultFormatNode, parse_result_format, and the entity validation in convert_query are all there, but result_format is never passed through to the return dict or the streaming layer in read.py, so the response is always JSON regardless of what $resultFormat is set to. Only dataArray appears to have any downstream handling.

This PR only fixes the 500 and the wrong error code. The actual serialization is a separate feature that needs to be built. I am opening a separate issue for that.

References

OGC SensorThings API Part 1, Section 9.3.4 => valid $resultFormat values are dataArray, CSV, and GeoJSON.

Screenshot 2026-05-29 151333 Screenshot 2026-05-29 151232

@Vishmayraj Vishmayraj changed the title fix: resultFormat CSV and GeoJSON support broken in STA parser fix: $resultFormat=CSV and GeoJSON crash server with 500, parser token missing May 31, 2026
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.

1 participant