GeezerVison is showing github.com — Query with projection on datetime entity doesn't deserialize to datetime · Issue #1770 · googleapis/google-cloud-python
Query with projection on datetime entity doesn't deserialize to datetime #1770Labels api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionIf you do a query and the projection has a datetime field, for instance:
entity = client.entity(client.key('example'))
entity['created'] = datetime.datetime.utcnow()
query = client.query(kind='example')
query.projection = ['created']
results = list(query.fetch())
The results[0]['created'] will be a timestamp instead of a datetime object. Reacted by James Maidment and CloudFramework Academy Activityadded type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on May 3, 2016changed the title [-]Query with projection on datetime entity doesn't deserialized to datetime[/-] [+]Query with projection on datetime entity doesn't deserialize to datetime[/+] on May 3, 2016tseaver commented on May 3, 2016 For the query results, instead of returning what should be a timestamp_value, the back-end is returning an integer_value with meaning of 18):
>>> result_pbs[0]
[key {
partition_id {
project_id: "citric-celerity-697"
}
path {
kind: "issue-1770"
id: 5754903989321728
}
}
properties {
key: "created"
value {
integer_value: 1462299971643047
meaning: 18
}
}
]
which differs from the protobuf returned via a normal get:
>>> epbs
[key {
partition_id {
project_id: "citric-celerity-697"
}
path {
kind: "issue-1770"
id: 5754903989321728
}
}
properties {
key: "created"
value {
timestamp_value {
seconds: 1462299971
nanos: 643047000
}
}
}
]
That smells like a back-end bug to me. theacodes commented on May 3, 2016 ContributorAuthor More actions tseaver commented on May 3, 2016 Extra datapoint: the result from the same query without the projection return the expected timestamp_value property. pcostell commented on May 3, 2016 This is WAI (or WADNAI if you prefer -- Working as Designed, not as intended). timestamp_value is stored as a a fixed-point number in Cloud Datastore. You can see this in the sort order specification, Integers and Date/times are listed together in the sort order.
In the indexes, the property value is stored without additional information, in this case the indication that this is a datetime. In Cloud Datastore, projection queries aren't just field masks -- they indicate to the system that it should only perform an index scan and not do the full entity lookup. This means it won't have the opportunity to lookup the additional information.
We hope to be able to fix this eventually, but it has a large impact on backwards compatibility. theacodes commented on May 3, 2016 ContributorAuthor More actions Wow, that's kind of a really bad experience for using projection queries. pcostell commented on May 3, 2016 The price we have to pay for backwards compatibility I'm afraid. tseaver commented on May 3, 2016 AFAICT, there is nothing gcloud-python can do to fix this issue. @jonparrott / @pcostell feel free to reopen if you have a suggestion. dhermes commented on May 3, 2016 dhermes commented on May 3, 2016 pcostell commented on May 3, 2016 I'm not sure there is anything to do. The 18 just signifies that this came from a projection query. It's useful if the user tries to store that property again we can reject it (to prevent data loss from reading a subset of your data then overwriting the real data). dhermes commented on May 3, 2016 pdknsk commented on Oct 7, 2017 I ran into this and agree it's bad. At the least you'd expect a warning about it in the docs. Even when it's not too difficult to guess what's happening when it returns long rather than datetime.datetime.
MetadataMetadataapi: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|