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

Datastore query throws exception when querying an entity that has a double property of 1.0 #45

Closed
avoivo opened this issue May 19, 2017 · 3 comments

Comments

@avoivo
Copy link

avoivo commented May 19, 2017

Hello, i am using gcloud's datastore library and stumble into a strange problem. When i query on an entity that has a double value property without precision (ie 1.00, 2.00) , the following exception is thrown.

Unhandled exception:
type 'int' is not a subtype of type 'double' of 'value' where
  int is from dart:core
  double is from dart:core

#0      Value.doubleValue= (package:googleapis/datastore/v1.dart:1870:15)
#1      Value.Value.fromJson (package:googleapis/datastore/v1.dart:1927:7)
#2      Entity.Entity.fromJson.<anonymous closure> (package:googleapis/datastore/v1.dart:614:70)
#3      mapMap.<anonymous closure> (package:_discoveryapis_commons/src/clients.dart:916:28)
#4      _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:348)
#5      mapMap (package:_discoveryapis_commons/src/clients.dart:911:10)
#6      Entity.Entity.fromJson (package:googleapis/datastore/v1.dart:614:20)
#7      EntityResult.EntityResult.fromJson (package:googleapis/datastore/v1.dart:666:20)
#8      QueryResultBatch.QueryResultBatch.fromJson.<anonymous closure> (package:googleapis/datastore/v1.dart:1619:65)
#9      MappedListIterable.elementAt (dart:_internal/iterable.dart:412)
#10     ListIterable.toList (dart:_internal/iterable.dart:219)
#11     QueryResultBatch.QueryResultBatch.fromJson (package:googleapis/datastore/v1.dart:1619:95)
#12     RunQueryResponse.RunQueryResponse.fromJson (package:googleapis/datastore/v1.dart:1822:19)
#13     ProjectsResourceApi.runQuery.<anonymous closure> (package:googleapis/datastore/v1.dart:307:41)
#14     _rootRunUnary (dart:async/zone.dart:1158)
#15     _CustomZone.runUnary (dart:async/zone.dart:1037)
#16     _FutureListener.handleValue (dart:async/future_impl.dart:131)
#17     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:637)
#18     _Future._propagateToListeners (dart:async/future_impl.dart:667)
#19     _Future._complete (dart:async/future_impl.dart:467)
#20     Stream.join.<anonymous closure> (dart:async/stream.dart:685)
#21     _rootRun (dart:async/zone.dart:1146)
#22     _CustomZone.run (dart:async/zone.dart:1026)
#23     _CustomZone.runGuarded (dart:async/zone.dart:924)
#24     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:384)
#25     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#26     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:278)
#27     _SinkTransformerStreamSubscription._close (dart:async/stream_transformers.dart:95)
#28     _EventSinkWrapper.close (dart:async/stream_transformers.dart:18)
#29     _StringAdapterSink.close (dart:convert/string_conversion.dart:267)
#30     _Utf8ConversionSink.close (dart:convert/string_conversion.dart:324)
#31     _ConverterStreamEventSink.close (dart:convert/chunked_conversion.dart:96)
#32     _SinkTransformerStreamSubscription._handleDone (dart:async/stream_transformers.dart:140)
#33     _rootRun (dart:async/zone.dart:1146)
#34     _CustomZone.run (dart:async/zone.dart:1026)
#35     _CustomZone.runGuarded (dart:async/zone.dart:924)
#36     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:384)
#37     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#38     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:278)
#39     _ForwardingStream._handleDone (dart:async/stream_pipe.dart:116)
#40     _ForwardingStreamSubscription._handleDone (dart:async/stream_pipe.dart:184)
#41     _rootRun (dart:async/zone.dart:1146)
#42     _CustomZone.run (dart:async/zone.dart:1026)
#43     _CustomZone.runGuarded (dart:async/zone.dart:924)
#44     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:384)
#45     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#46     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:278)
#47     _SinkTransformerStreamSubscription._close (dart:async/stream_transformers.dart:95)
#48     _EventSinkWrapper.close (dart:async/stream_transformers.dart:18)
#49     _ByteAdapterSink.close (dart:convert/byte_conversion.dart:68)
#50     _FilterSink.close (dart:io/data_transformer.dart:524)
#51     _ConverterStreamEventSink.close (dart:convert/chunked_conversion.dart:96)
#52     _SinkTransformerStreamSubscription._handleDone (dart:async/stream_transformers.dart:140)
#53     _rootRun (dart:async/zone.dart:1146)
#54     _CustomZone.run (dart:async/zone.dart:1026)
#55     _CustomZone.runGuarded (dart:async/zone.dart:924)
#56     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:384)
#57     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#58     _BufferingStreamSubscription._close (dart:async/stream_impl.dart:278)
#59     _ForwardingStream._handleDone (dart:async/stream_pipe.dart:116)
#60     _ForwardingStreamSubscription._handleDone (dart:async/stream_pipe.dart:184)
#61     _rootRun (dart:async/zone.dart:1146)
#62     _CustomZone.run (dart:async/zone.dart:1026)
#63     _CustomZone.runGuarded (dart:async/zone.dart:924)
#64     _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:384)
#65     _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:394)
#66     _DelayedDone.perform (dart:async/stream_impl.dart:609)
#67     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706)
#68     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:666)
#69     _rootRun (dart:async/zone.dart:1150)
#70     _CustomZone.run (dart:async/zone.dart:1026)
#71     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:953)
#72     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#73     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#74     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:394)
#75     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:414)
#76     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)



I have created an example of the behavior HERE

@mkustermann
Copy link
Member

Thanks for the bug report @avoivo !

You appear to be using package:gcloud/src/datastore_impl.dart (which internally is based upon package:googleapis/datastore/v1.dart which uses a JSON based api). So it appears that the query result returned by the server does not encode the double value as a doubles in the JSON response but rather as integers if it's a whole number (javascript does not know the difference either).

If at all, it is a bug in the discoveryapis_generator, but the schema actually specifies it is a double value (see schema). Maybe we should move the issue over there - it could probably be fixed by calling toDouble() on values returned from the server which are specified to be of type double.

Longer term we will not be using the json-based API anymore.

The package:appengine is using internally a gRPC-based implementation of datastore. Are you using the package:appengine?

@avoivo
Copy link
Author

avoivo commented May 23, 2017

Hello @mkustermann and thank you for your detailed reply.

After some research, me and a colleague of mine found out about the gRPC-based implementation of datastore that exists inside the appengine and decided to give it a try. It worked.

Long story short, we have implemented a rest api written in dart that runs on googles container engine and my question is , is it safe to use the gRPC-based implementation of datastore in production?

@avoivo
Copy link
Author

avoivo commented May 24, 2017

Closing this in favor of google/googleapis.dart#18

@avoivo avoivo closed this as completed May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants