Skip to content

Firestore client library's limit API not handling limit(0) correctly #2461

@liu-husong

Description

@liu-husong

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

Not applicable

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

e006f02

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

The link includes a regression test that is expected to fail — it demonstrates the current buggy behaviour.

Another way to reproduce this (which is how I originally ran into the issue) is to spin up a local Firestore emulator, write a unit test that inserts several documents, and then query with limit(0). You’ll see that the result is unexpectedly non-empty.

A clear and concise description of what the bug is, and what you expected to happen.

When users of the query library call limit(0), the client does not actually include the limit in the request protos.

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

This looks like an oversight. Semantically, limit(0) is a valid query. There’s also validation logic in the limit implementation that explicitly does not rule out 0 as a value:

validateInteger('limit', limit);

One could argue that limit(0) should simply behave as if no limit were applied. However, if that’s the intended behaviour, the validation logic should likely reject 0 values, and the library should warn users about this surprising behaviour when 0 is provided.

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions