FrankChen021 opened a new pull request, #19775:
URL: https://github.com/apache/druid/pull/19775

   ### 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 `ValueInstantiationException` failures into HTTP 
400 responses and exposes the underlying validation message. For example:
   
   ```json
   {
     "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 `errorMessage` helps users, 
programmatic clients, and AI agents identify and repair the generated native 
query.
   
   If no underlying validation message is available, the response uses:
   
   ```text
   Invalid native query: the request contains invalid or missing fields
   ```
   
   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.
   
   <hr>
   
   ##### Key changed classes in this PR
   
   - `BadJsonQueryException`
   - `QueryResource`
   - `QueryResourceTest`
   
   <hr>
   
   This PR has:
   
   - [x] been self-reviewed.
   - [x] a release note entry in the PR description.
   - [x] added unit tests covering the new error-handling path.
   
   ### Testing
   
   The focused malformed-JSON and incomplete-query tests passed before rebasing 
the change onto current `master`:
   
   ```bash
   mvn test -pl server -am \
     
-Dtest="org.apache.druid.server.QueryResourceTest#testBadQuery+testIncompleteQuery"
 \
     -Dsurefire.failIfNoSpecifiedTests=false \
     -Pskip-static-checks \
     -Dweb.console.skip=true \
     -T1C
   ```
   
   Result: 2 tests run, 0 failures, 0 errors.
   
   After rebasing onto current `master`, local validation stops during 
compilation because the available JDK is 21 while Druid now compiles with 
`--release 25`:
   
   ```text
   Fatal error compiling: error: release version 25 not supported
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to