Order diff between backend and client with order_by_key()

Open
#677 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
database

Research direction

Reproduce the report with db.reference("/test").order_by_key().limit_to_first(4).get() using the supplied JSON and compare the OrderedDict order with Firebase's order_by_key behavior. Trace the response handling for this query and verify that the returned keys preserve the database order so pagination with start_at does not repeat results.

Written by the indexing model from the issue text.

Description

api: database
Describe your environment
  • Operating System version: macOS 12.4
  • Firebase SDK version: 6.1.0
  • Firebase Product: database
  • Python version: 3.7.9
  • Pip version: 21.3.1
Describe the problem

When using order_by_key(), the order of the returned OrderedDict is not the same as the database making pagination very difficult

Steps to reproduce:
  • Create a collection with this json in "/test" for example :
{
  "123": {"myValue": true},
  "100001": {"myValue": true},
  "100002": {"myValue": true},
  "100003": {"myValue": true},
  "100004": {"myValue": true},
  "100005": {"myValue": true}
}
  • Query it with :
db.reference("/test").order_by_key().limit_to_first(4).get()
  • Comparison :

Current :

OrderedDict([('100001', {'myValue': True}), ('100002', {'myValue': True}), ('100003', {'myValue': True}), ('123', {'myValue': True})])

Expected :

OrderedDict([('123', {'myValue': True}), ('100001', {'myValue': True}), ('100002', {'myValue': True}), ('100003', {'myValue': True})])
Comments

So according to this link, order should be the same as the collection but in the corresponding OrderedDict the order is not the same so if you want make a pagination strategy, it just loops as getting the last key of the OrderedDict returned and using it in start_at will return the same result over and over again.

Dominant language
Python
Stars
1.2k
Forks
359
Avg merge
5d 6m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebase-admin-python

All issues in firebase/firebase-admin-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.