Angularfire: Queries with null don't work as expected

Created on 30 Nov 2016  路  13Comments  路  Source: angular/angularfire

Version info

Angular: 2.2.3

Firebase: 3.6.1

AngularFire: 2.0.0-beta.6

How to reproduce these conditions

Stackoverflow: AngularFire2: query if child exists

Firebase Google Group: AngularFire2 query with null doesn't work

Steps to set up and reproduce Sample data and security rules

See Stackoverflow question above.

Expected behavior

Queries with given ordeByChild: "property" and endAt : null is expected to filter out lists where those poperties are null/don't exist.

Actual behavior

Whole list is returned with no filtering.

As @cartant pointed out, check could be done here just against undefined maybe and not to null.

All 13 comments

Can confirm.

Currently using null just ignores that part of the query, so for example using equalTo: null will just return the whole list.

Is there a way we could allow null value checking and also resetting certain query properties?

Thanks for the report. Does look like this could be fixed. Please include a minimal repro of the issue or a failing test case we can use as a marker for verifying and fixing.

All issues have to follow the issue template provided, including a minimal repro or failing test case. This is critical to keep things streamlined and manageable.

I'm very displeased such a good project managed in such bad manner lately. The error case is very simple to reproduce. I can't believe people managing the project don't have sample projects at hand to test stuff out.
You guys are like just trying to push people out from this report section on purpose.

@katowulf I'm not planing to spare more time on this and creating a repro. So please close this (if you want) and lets keep this project buggy so that in future people can choose alternative frameworks and cloud services for their projects.

@bogacg There are around 500 issues reported across the Firebase repositories (not counting the plethora specific to Angular projects) daily. Each takes around 15-30m to reproduce. As you can imagine, those add up, and most turn out to be red herrings. This one looks valid, as you've noted. But, just help a brother out and follow the rules by saving us some time and energy.

@katowulf There is a Plunker that reproduces the issue here. The relevant code is in app/app.component.ts.

The fix would be pretty minor; all that should be required is for this line:

if (utils.isPresent(query.equalTo)) {

to be changed to:

if (query.equalTo !== undefined) {

If I have time, tomorrow, I'll submit a PR.

Thanks. I think that the misleading method name here has probably resulted in this obscure bug. We should probably proceed as follows:

  • Remove utils.isPresent() (which is a misleading name)
  • Create utils.isEmpty(<any>: val) (still not perfectly happy with this name; suggestions welcome)
  • Change current usages (about 5) of utils.isPresent() to !utils.isEmpty()
  • Add utils.hasKey(Object: o, String: key), which can just return o[key] !== undefined
  • Set this particular usage to if( utils.hasKey(query, 'equalTo') )

@katowulf Regarding utils.isEmpty, lodash has a similar function named isNil. Would that name be preferred? Or isNullish?

This issue still persists with latest versions:
Plunkr

@bogacg Indeed, it is still broken. Apparently, I missed replacing the isNil calls in the query observable with calls to hasKey - so the equalTo is dropped from the query before it's later tested to be passed to the SDK. I will fix it and will add some tests, this time.

@bogacg See #809.

i will have the issue, null here does not work

      this.notmybooks = angfire.database.list('/user-books', {
        query: {
          orderByChild: 'likedby/tzROGF1Tk4NcobrTE70ZKQzoKom1',
          equalTo: null
        }
      });

@leeandro0 try equalTo: undefined, this work for me.

My quick this is shown below.

  this.notmybooks = angfire.database.list('/user-books', {
    query: {
      orderByChild: 'likedby/tzROGF1Tk4NcobrTE70ZKQzoKom1',
      equalTo: book==null ?"" : book //fix null values returning whole list
    }
  });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriandurran picture adriandurran  路  3Comments

jnupeter picture jnupeter  路  3Comments

StephenFluin picture StephenFluin  路  3Comments

martinyoussef picture martinyoussef  路  3Comments

Sun3 picture Sun3  路  3Comments