firebase / firebase/firebase-ios-sdk

Possible bug in “queryOrdered(byChild:).queryEqual(toValue:).getData" function

Open
#8,286 6 comments 0 reactions 1 assignee Claimed by @jmwski View on GitHub
api: database
Dominant language
C++
Stars
6.7k
Forks
1.8k
Avg merge
2d 14h
Merged PRs (30d)
72

Description

### [REQUIRED] Step 1: Describe your environment

* Xcode version: Version 12.5 (12E262)
* Firebase SDK version: 8.1.1
* Installation method: Swift Package Manager
* Firebase Component: Database

### [REQUIRED] Step 2: Describe the problem

#### Steps to reproduce:

What happened? How can we make the problem occur?
I’m observing how many children a person called "james" has using child("james").child("children").observe(.value) function, in my case he has 2 children called "child1" and "child2" so it prints children count = 2. Then I check if "james" has a child called "child2" using child("james").child("children").queryOrdered(byChild: "name").queryEqual(toValue: "child2").getData function, in my case he has a child called "child2" so it prints found. Then unexpectedly the first observe function that observes and prints children count triggers again and prints children count = 1. I think the first observe function should not trigger and the children’s count should remain at 2. If I replace getData function with observe function to search for a child named "child2" it finds it and prints found and the first observe function that observes and prints children count does not trigger and the children count remains 2.

If you have a downloadable sample project that reproduces the bug you're reporting, you will
likely receive a faster response on your issue.
https://github.com/fawzialrifai/People

#### Relevant Code:
```
import UIKit
import Firebase

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
Database.database().reference().child("james").child("children").observe(.value) { snapshot in
print("number of james children = \(snapshot.childrenCount)") // observe and print james children count
}
Database.database().reference().child("james").child("children").queryOrdered(byChild: "name").queryEqual(toValue: "child2").getData { error, snapshot in
if snapshot.exists() { // search for james child named child2
print("found")
} else {
print("not found")
}
}
}

}
```

Screen Shot 2021-06-22 at 10 46 31 PM

Screen Shot 2021-06-22 at 11 39 15 PM

Screen Shot 2021-06-22 at 10 53 35 PM

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.