GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #1770

New issue
Copy link
New issue
Copy link
Closed
Closed
Query with projection on datetime entity doesn't deserialize to datetime#1770
Copy link
Assignees
tseaver
Labels
api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@theacodes
theacodes
opened on May 3, 2016
Issue body actions

If 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

Activity

  1. theacodes
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: datastoreIssues related to the Datastore API.
    on May 3, 2016
  2. dhermes
    changed 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, 2016
  3. tseaver commented on May 3, 2016

    @tseaver
    tseaver
    on May 3, 2016
    Contributor
    More actions

    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.

  4. theacodes commented on May 3, 2016

    @theacodes
    theacodes
    on May 3, 2016
    ContributorAuthor
    More actions

    Oh noes.

    /cc @jgeewax @pcostell

  5. tseaver commented on May 3, 2016

    @tseaver
    tseaver
    on May 3, 2016
    Contributor
    More actions

    Extra datapoint: the result from the same query without the projection return the expected timestamp_value property.

  6. pcostell commented on May 3, 2016

    @pcostell
    pcostell
    on May 3, 2016
    Contributor
    More actions

    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.

  7. theacodes commented on May 3, 2016

    @theacodes
    theacodes
    on May 3, 2016
    ContributorAuthor
    More actions

    Wow, that's kind of a really bad experience for using projection queries.

  8. pcostell commented on May 3, 2016

    @pcostell
    pcostell
    on May 3, 2016
    Contributor
    More actions

    The price we have to pay for backwards compatibility I'm afraid.

  9. tseaver commented on May 3, 2016

    @tseaver
    tseaver
    on May 3, 2016
    Contributor
    More actions

    AFAICT, there is nothing gcloud-python can do to fix this issue. @jonparrott / @pcostell feel free to reopen if you have a suggestion.

  10. tseaver
    closed this as completedon May 3, 2016
  11. dhermes commented on May 3, 2016

    @dhermes
    dhermes
    on May 3, 2016
    Contributor
    More actions

    @pcostell Any suggestions for what to do for users? It seems that 18 is for INDEX_VALUE which is pretty generic.

  12. dhermes commented on May 3, 2016

    @dhermes
    dhermes
    on May 3, 2016
    Contributor
    More actions

    @pcostell Any suggestions for what to do for users? It seems that 18 is for INDEX_VALUE which is pretty generic.

  13. pcostell commented on May 3, 2016

    @pcostell
    pcostell
    on May 3, 2016
    Contributor
    More actions

    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).

  14. dhermes commented on May 3, 2016

    @dhermes
    dhermes
    on May 3, 2016
    Contributor
    More actions

    OK. Le sad face.

  15. pdknsk commented on Oct 7, 2017

    @pdknsk
    pdknsk
    on Oct 7, 2017
    More actions

    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.

  16. JustinBeckwith
    assigned
    tseaver
    on Feb 1, 2021
  17. parthea
    added a commit that references this issue on Nov 22, 2025

    docs: add samples from bigtable (#38)

    ab589eb
  18. parthea
    added a commit that references this issue on Mar 6, 2026

    docs: update the query with no cache sample to use query_and_wait API (…

    d55f788
  19. parthea
    added a commit that references this issue on Sep 8, 2026

    docs: migrate code from googleapis/python-bigquery (#18303)

    23f9a74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

Labels

api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.