Skip to content

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

@fawzialrifai

Description

@fawzialrifai

[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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions