You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by "brucearctor (via GitHub)" <gi...@apache.org> on 2026/03/15 23:18:00 UTC

[PR] (#9183) - Fix null pointer exception when searching with index for missing field [pouchdb]

brucearctor opened a new pull request, #9199:
URL: https://github.com/apache/pouchdb/pull/9199

   ## Summary
   
   Fixes #9183.
   
   When performing a `find()` query that uses an index, if one of the documents in the database is **missing the indexed field**, `filterInclusiveStart` throws a `TypeError: can't convert null to object` from inside `pouchdb-collate`.
   
   ## Root Cause
   
   `filterInclusiveStart` calls `getKeyFromDoc` to extract the indexed key from each document. When a document doesn't have the indexed field, `getKeyFromDoc` returns `undefined` for that field. This `undefined` value is then passed to `collate()`, which crashes.
   
   ## Fix
   
   Added a guard in `filterInclusiveStart` to skip any document whose key is `undefined` (i.e. the document is missing the indexed field). This matches standard CouchDB behaviour, where documents missing a field are excluded from an index.
   
   ## Testing
   
   Added a regression test in `tests/find/test-issues/test.issue9183.js` that inserts two documents (one with the indexed field, one without) and verifies that querying with the index does not throw and returns only the matching document.


-- 
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: commits-unsubscribe@pouchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org