firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

startAfter and endBefore throw with no key argument when using REST

Open tonyhallett opened this issue 1 year ago • 3 comments

Operating System

Windows 11

Environment (if applicable)

Version 128.0.6613.115 (Official Build) (64-bit)

Firebase SDK Version

^10.12.2

Firebase SDK Product(s)

Database

Project Tooling

React, typescript with Parcel

Detailed Problem Description

use constrainsts startAfter and endBefore without keys using REST.

"{ "error" : "Constraint key field must be a valid key name" } "

Due to the placeholders MAX_NAME and MIN_NAME being included in the generated url. startAfter(2) "http://127.0.0.1:9000/things.json?ns=mydb-default-rtdb&orderBy=%22pNumber%22&startAfter=2%2C%22%5BMAX_NAME%5D%22&format=export"

endBefore(2) http://127.0.0.1:9000/things.json?ns=mydb-default-rtdb&orderBy=%22pNumber%22&endBefore=2%2C%22%5BMIN_NAME%5D%22&format=export

See https://github.com/firebase/firebase-js-sdk/blob/15c36cc7a6d1024147062fcbb0f6df0de8e5bb12/packages/database/src/core/view/QueryParams.ts#L277 https://github.com/firebase/firebase-js-sdk/blob/15c36cc7a6d1024147062fcbb0f6df0de8e5bb12/packages/database/src/core/view/QueryParams.ts#L313

If being crawled will use REST https://github.com/firebase/firebase-js-sdk/blob/15c36cc7a6d1024147062fcbb0f6df0de8e5bb12/packages/database/src/core/Repo.ts#L218

Steps and code to reproduce issue

//Links in problem description should suffice

tonyhallett avatar Sep 07 '24 12:09 tonyhallett

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Sep 07 '24 12:09 google-oss-bot

Hi @tonyhallett, I don't fully understand the issue. Please share more information including

  • What you're trying to do
  • What the expected behaviour is
  • What the real behaviour is
  • Code snippets to help us reproduce the issue

dlarocque avatar Sep 13 '24 15:09 dlarocque

What you're trying to do Use startAt or endBefore in a query

What the expected behaviour is It works when the js sdk uses REST due to being crawled ( or have manually created a Repo that forces REST ).

What the real behaviour is "{ "error" : "Constraint key field must be a valid key name" } "

Code snippets to help us reproduce the issue Given a list of things where a Thing has a field pNumber onValue(query(ref(db,"things"), orderByChild("pNumber"), startAt(2)), (snapshot) => { });

To see the error you will need to add a break point in the constructor for the Repo class and set the forceRestClient to true.

  constructor(
    public repoInfo_: RepoInfo,
    public forceRestClient_: boolean,
    public authTokenProvider_: AuthTokenProvider,
    public appCheckProvider_: AppCheckTokenProvider
  ) {
    // This key is intentionally not updated if RepoInfo is later changed or replaced
    this.key = this.repoInfo_.toURLString();
  }

tonyhallett avatar Sep 13 '24 19:09 tonyhallett