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 — Datastore Query generates Bad Request with select+filter attached. · Issue #1016 · googleapis/google-cloud-node

Datastore Query generates Bad Request with select+filter attached. #1016

New issue
Copy link
New issue
Copy link
Closed
Closed
Datastore Query generates Bad Request with select+filter attached.#1016
Copy link
Assignees
chriseaton
Labels
api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@chriseaton
chriseaton
opened on Dec 11, 2015
Issue body actions

I have a pretty basic entity and am attempting to leverage a query to select it. But when I use the "select" function on the query (in conjunction with a "filter"), and then run the query, it generates a Bad Request error. Removing the "select" allows the query to run ok.

I can run either select or filter independently and they both work ok.

Failing query:

var qry = ds.createQuery('SocialMedia')
    .select(['id'])
    .filter('id =', items[0].id);
ds.runQuery(qry, function(err, entities) {
 ...

Creates Error:

{"errors":[],"code":400,"message":"Bad Request","response":{
"statusCode":400,"body":{"type":"Buffer","data": ...

Running

var qry = ds.createQuery('SocialMedia')
    .filter('id =', items[0].id);
ds.runQuery( ...

or

var qry = ds.createQuery('SocialMedia')
    .select(['id'])
ds.runQuery( ...

works fine and returns the results expected.

Activity

  1. stephenplusplus commented on Dec 11, 2015

    @stephenplusplus
    stephenplusplus
    on Dec 11, 2015
    Contributor
    More actions

    Thanks for reporting! @pcostell is this us or an issue of indexes?

  2. stephenplusplus
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: datastoreIssues related to the Datastore API.
    on Dec 11, 2015
  3. chriseaton commented on Dec 11, 2015

    @chriseaton
    chriseaton
    on Dec 11, 2015
    Author
    More actions

    Hi - some added information - and maybe this is why there is this issue... The "id" column that I'm trying to filter/select is not indexed. Does the gcloud lib support tagging fields as indexed?

  4. pcostell commented on Dec 11, 2015

    @pcostell
    pcostell
    on Dec 11, 2015
    Contributor
    More actions

    Yes, the id must be indexed, but it should be indexed by default. In fact
    if you get results where you query for id = ... then it is indexed.
    However, the issue you are hitting is that you can't project something
    involved in an equality:

    https://cloud.google.com/datastore/docs/concepts/projectionqueries#Datastore_Limitations_on_projections

    Is there not more information in the returned error message? I think the
    error that should be returned calls this out explicitly.

    On Fri, Dec 11, 2015, 3:33 PM Christopher Eaton [email protected]
    wrote:

    Hi - some added information - and maybe this is why there is this issue...
    The "id" column that I'm trying to filter/select is not indexed. Does
    the gcloud lib support tagging fields as indexed?

    —
    Reply to this email directly or view it on GitHub
    #1016 (comment)
    .

  5. chriseaton commented on Dec 11, 2015

    @chriseaton
    chriseaton
    on Dec 11, 2015
    Author
    More actions

    Hi @pcostell,
    Unfortunately there isn't a message like that, here's the err object in full minus my gc project id:

    quick link to json parser

    {"errors":[],"code":400,"message":"Bad Request","response":{"statusCode":400,"body":{"type":"Buffer","data":[67,97,110,110,111,116,32,117,115,101,32,112,114,111,106,101,99,116,105,111,110,32,111,110,32,97,32,112,114,111,112,101,114,116,121,32,119,105,116,104,32,97,110,32,101,113,117,97,108,105,116,121,32,102,105,108,116,101,114,46]},"headers":{"vary":"X-Origin, Origin,Accept-Encoding","content-type":"text/html; charset=UTF-8","date":"Fri, 11 Dec 2015 23:38:46 GMT","expires":"Fri, 11 Dec 2015 23:38:46 GMT","cache-control":"private, max-age=0","x-content-type-options":"nosniff","x-frame-options":"SAMEORIGIN","x-xss-protection":"1; mode=block","server":"GSE","alternate-protocol":"443:quic,p=0","alt-svc":"clear","accept-ranges":"none","connection":"close"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"www.googleapis.com","port":443,"hostname":"www.googleapis.com","hash":null,"search":null,"query":null,"pathname":"/datastore/v1beta2/datasets/xxxx/runQuery","path":"/datastore/v1beta2/datasets/xxxx/runQuery","href":"https://www.googleapis.com/datastore/v1beta2/datasets/xxxx/runQuery"},"method":"POST","headers":{"Content-Type":"application/x-protobuf","Authorization":"Bearer xxxx","User-Agent":"gcloud-node/0.24.1","content-length":68}}}}
    
  6. chriseaton commented on Dec 11, 2015

    @chriseaton
    chriseaton
    on Dec 11, 2015
    Author
    More actions

    However, the issue you are hitting is that you can't project something involved in an equality:

    Thanks! That's it, if I change the op to something other than equality it works.

  7. chriseaton
    closed this as completedon Dec 11, 2015
  8. pcostell commented on Dec 12, 2015

    @pcostell
    pcostell
    on Dec 12, 2015
    Contributor
    More actions

    Turns out the data of the response body is an ascii array which says:
    "'Cannot use projection on a property with an equality filter.'"

    @stephenplusplus - maybe the body should get parsed into a string?
    @eddavisson - any idea why the JSON is getting sent like this?

  9. stephenplusplus commented on Dec 14, 2015

    @stephenplusplus
    stephenplusplus
    on Dec 14, 2015
    Contributor
    More actions

    I believe the body is being returned as a Buffer because that's just how the request library we're using does it. We wrap that raw response and return it in our custom ApiError type.

    I played around with a 412 - Precondition Failed error. The response body is a buffer, but stringified (err.response.body.toString()) is something like no matching index found. When we return our custom ApiError to the user, we use the HTTP status message as the "message" to associate with the error. When you console.log or throw an error, the message is what's displayed. Maybe we should use that in combination with the parsed response.body, if it exists?

    In this case, it would look like:

    console.log(err);
    // Precondition Failed - no matching index found.
    

    // @callmehiphop

  10. JustinBeckwith
    assigned
    chriseaton
    on Feb 1, 2021
  11. sofisl
    added a commit that references this issue on Jan 17, 2023

    build!: update library to use Node 12 (#1016)

    ce7a319
  12. miguelvelezsa
    added a commit that references this issue on Jul 23, 2025

    chore: release 2.14.1 (#1016)

    a3c06a2
  13. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    fix: regenerated protos JS and TS definitions (#1016)

    1ec5e75
  14. sofisl
    added a commit that references this issue on Feb 5, 2026

    fix: regenerated protos JS and TS definitions (#1016)

    aedad09
  15. sofisl
    added a commit that references this issue on Feb 17, 2026

    fix: regenerated protos JS and TS definitions (#1016)

    acdc058
  16. sofisl
    added a commit that references this issue on Feb 24, 2026

    feat!: Drop Node 8 support (#1006)

    2500a99
  17. GautamSharda
    added 2 commits that reference this issue on Mar 5, 2026

    test: add environment tests on Cloud Run (#1016)

    5b32d63

    docs: update list of available samples (#1016)

    311b1b0
  18. feywind
    added a commit that references this issue on Mar 27, 2026

    docs: update list of available samples (#1016)

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

Metadata

Metadata

Assignees

  • @chriseaton
    chriseaton

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.