nick-boss-tech opened a new pull request, #5158: URL: https://github.com/apache/solr/pull/5158
🤖 *AI text below* 🤖 *(posted on behalf of Nick Shanin)* https://issues.apache.org/jira/browse/SOLR-10305 ## What happens today **A distributed query fails with a NullPointerException when the schema has no uniqueKey field.** A distributed query is one that runs across shards, such as a request with a `shards` parameter. The code reads the unique key name when it builds the shard request, before any shard has answered, so a missing field fails there ([createMainQuery, at the base commit `cabedd1d968`](https://github.com/nick-boss-tech/solr/blob/cabedd1d968059215188f4e7563fb303241899ed/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L793)). In a standalone server where the URL allow list is on (the default) and no allow list is set, the request is refused with a 403 before query preparation. The NullPointerException is reached in SolrCloud and on a server where the allow list is turned off ([HttpShardHandler check, base commit](https://github.com/nick-boss-tech/solr/blob/cabedd1d968059215188f4e7563fb303241899ed/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java#L482-L492)). ## What this change does **A distributed request on a schema with no uniqueKey field now gets a 400 error with a clear message.** `QueryComponent.prepare` checks the schema inside the distributed branch. If there is no uniqueKey field, it throws a `BAD_REQUEST` error with the message "Distributed search requires a uniqueKey field in the schema" ([head `86ddbd433dba`](https://github.com/nick-boss-tech/solr/blob/86ddbd433dba9852f30880b184b3ec2bc14180e4/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java#L148-L153)). The check runs before any shard request is built. Grouped distributed requests reach the same check. On the base code they also failed before any shard answered, with a NullPointerException in the first grouped phase ([base commit](https://github.com/nick-boss-tech/solr/blob/cabedd1d968059215188f4e7563fb303241899ed/solr/core/src/java/org/apache/solr/search/grouping/distributed/requestfactory/SearchGroupsRequestFactory.java#L77-L79)). Behavior change, stated openly: a request that failed with a NullPointerException now fails with a 400. The change adds no other behavior. ## Proof **The new test fails on the base code and passes with this change.** `MinimalSchemaTest` passes 4 of 4 at head `86ddbd433dba`, recorded 2026-10-14. The new test is `testDistributedQueryWithoutUniqueKeyIsBadRequest`. On the base code, with the same test in place, the class has exactly one failure: that test. The request gets past the allow-list check and reaches the distributed code instead of the expected 400. ## Limits **The test turns off the URL allow-list check for its own class, and the default standalone case still returns 403.** - The check is turned off only in `MinimalSchemaTest` ([test setup](https://github.com/nick-boss-tech/solr/blob/86ddbd433dba9852f30880b184b3ec2bc14180e4/solr/core/src/test/org/apache/solr/MinimalSchemaTest.java#L37-L40)), as other tests in this repository do. The allow-list rules are unchanged. - A standalone server with the default allow list still returns the 403 before this check. Moving the 400 ahead of that check would change the order of a security check in shared code, so this change leaves it alone. A follow-up ticket and PR can cover it on request. - The proof is one standalone test class. No SolrCloud test run is recorded. - Other distributed code paths that read the unique key were not traced. Changelog: [changelog/unreleased/SOLR-10305-distributed-query-requires-unique-key.yml](https://github.com/nick-boss-tech/solr/blob/86ddbd433dba9852f30880b184b3ec2bc14180e4/changelog/unreleased/SOLR-10305-distributed-query-requires-unique-key.yml) ### AI assistance AI agents assisted with research, implementation, review, and drafting. Nick Shanin directed the work and takes responsibility for this contribution. -- 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]
