fix: return actionable errors for invalid native queries - #19775
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves native query error handling in Druid’s HTTP query endpoint by converting Jackson construction-time failures (notably ValueInstantiationException) into user-facing HTTP 400 responses with an actionable validation message, instead of allowing them to surface as opaque HTTP 500s.
Changes:
- Catch Jackson
ValueInstantiationExceptionduring query deserialization and rethrow asBadJsonQueryExceptionto produce HTTP 400. - Extend
BadJsonQueryExceptionto generate a clearer “Invalid native query: …” message when object construction fails. - Add a unit test covering an incomplete native query payload and asserting the new response shape/message.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
server/src/main/java/org/apache/druid/server/QueryResource.java |
Converts construction-time Jackson failures into BadJsonQueryException so they return HTTP 400. |
processing/src/main/java/org/apache/druid/query/BadJsonQueryException.java |
Adds handling/message formatting for ValueInstantiationException to produce actionable client error messages. |
server/src/test/java/org/apache/druid/server/QueryResourceTest.java |
Adds test coverage for incomplete native query payloads that fail during object construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@FrankChen021 this is related to #19745 |
|
@jtuglu1 Thanks for the link. The two PRs improve native-query errors at different stages: #19745 propagates |
FrankChen021
left a comment
There was a problem hiding this comment.
I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.
Since the prior review, production behavior is unchanged. The update moves exception-message tests into the owning processing module and adds safe coverage for empty and absent causes.
Reviewed 4 of 4 changed files.
This is an automated review by Codex GPT-5.6-Sol
Description
Native query deserialization currently handles malformed JSON as a client error, but query constructor validation failures escape as opaque HTTP 500 responses.
This is particularly problematic for AI agents that generate native queries. The existing response does not explain what is wrong, so the agent cannot reliably correct and retry its query.
This PR converts Jackson
ValueInstantiationExceptionfailures into HTTP 400 responses and exposes the underlying validation message. For example:{ "error": "Json parse failed", "errorMessage": "Invalid native query: dataSource can't be null", "errorClass": "com.fasterxml.jackson.databind.exc.ValueInstantiationException", "host": null }The HTTP 400 status identifies the request as invalid rather than a transient server failure, while the actionable
errorMessagehelps users, programmatic clients, and AI agents identify and repair the generated native query.If no underlying validation message is available, the response uses:
Exceptions occurring after query deserialization are unaffected.
Release note
Fixed: Invalid native queries that fail during object construction now return HTTP 400 with an actionable validation message. This helps users and automated clients, including AI agents, identify and correct invalid generated queries.
Key changed classes in this PR
BadJsonQueryExceptionQueryResourceQueryResourceTestThis PR has:
Testing
The local environment does not have JDK 25, so the focused tests were run on the rebased source using JDK 24 with the Java release property overridden to 24:
Result: 3 tests run, 0 failures, 0 errors. GitHub CI remains authoritative for the JDK 25 build.