Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisted queries should return ints instead of round doubles after int overwrites #91

Closed
collinjackson opened this issue Jun 20, 2017 · 2 comments
Assignees

Comments

@collinjackson
Copy link
Contributor

collinjackson commented Jun 20, 2017

This was originally flutter/flutter#10825 but it looks like a Firebase bug.

Environment

  • Xcode version: 8.3.3
  • Firebase SDK version: 4.0.2
  • Library version: 4.0.0
  • Firebase Product: database

Problem

Reduced test case:

#import "AppDelegate.h"
@import Firebase;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [FIRApp configure];
  [[FIRDatabase database] setPersistenceEnabled:YES];
  FIRDatabaseReference *ref = [[FIRDatabase database].reference child:@"counter"];
  [ref keepSynced:YES];
  [ref observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
    NSLog(@"Type of %@ is %d", snapshot.value, (int)CFNumberGetType((CFNumberRef)snapshot.value));
  }];
  [ref setValue:[NSNumber numberWithInt:42]];
  return YES;
}
@end

The first time this code runs, the snapshot value is an integer NSNumber. The second time, it's an NSDecimalNumber with a CFNumberType of kCFNumberDoubleType. Presumably this is because the persistent store is serializing numbers differently from the cloud Firebase. But Firebase queries should never yield doubles for round numbers like 42.

@collinjackson collinjackson changed the title Persisted queries should return ints instead of round doubles after overwrites Persisted queries should return ints instead of round doubles after int overwrites Jun 20, 2017
@schmidt-sebastian schmidt-sebastian self-assigned this Jun 21, 2017
@schmidt-sebastian
Copy link
Contributor

Thanks for sending this issue!

I was able to reproduce your observations. It turns out that NSJSONSerialization returns floating point numbers if the value is a top-level value. While {foo:1} returns a long, {1} returns a double. We will get this fixed in the next release.

@schmidt-sebastian
Copy link
Contributor

Addressed with #107

@firebase firebase locked and limited conversation to collaborators Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants