Skip to content

Datastore client not getting ProjectID from env  #1092

Description

@thesandlord

It looks like Datastore client is not getting the projectID from the env automatically.

var pubsub = gcloud.pubsub();

This works fine, but:

var dataset = gcloud.datastore.dataset();

returns:

Error: Sorry, we cannot connect to Google Cloud Services without a project ID. You may specify one with an environment variable named "GCLOUD_PROJECT". See https://googlecloudplatform.github.io/gcloud-node/#/authentication for a detailed guide on creating an authenticated connection.

This fixes the problem

var dataset = gcloud.datastore.dataset({projectId: process.env.GCLOUD_PROJECT});

Activity

  1. stephenplusplus commented on Jan 27, 2016

    @stephenplusplus
    Contributor

    Good catch, thanks for letting us know. PR incoming!

  2. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: datastoreIssues related to the Datastore API.
    on Jan 27, 2016
  3. thesandlord commented on Jan 27, 2016

    @thesandlord
    Author

    im not sure if other clients also have this problem. I though they all extend the same base class?

  4. stephenplusplus commented on Jan 27, 2016

    @stephenplusplus
    Contributor

    I checked, all of the other APIs do it.

    @callmehiphop can you think of a way we can move the normalizing to the Service constructor?

  5. callmehiphop commented on Jan 28, 2016

    @callmehiphop
    Contributor

    @stephenplusplus we should be able to just normalize them in the Service constructor, no?

  6. stephenplusplus commented on Jan 28, 2016

    @stephenplusplus
    Contributor

    I think there might be an issue with double-instantion?

    On Thu, Jan 28, 2016, 11:01 AM Dave Gramlich [email protected]
    wrote:

    @stephenplusplus https://github.com/stephenplusplus we should be able
    to just normalize them in the Service constructor, no?

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

  7. callmehiphop commented on Jan 28, 2016

    @callmehiphop
    Contributor

    Service.call(...) only gets called once IIRC - after a service class has been instantiated.. right?

  8. stephenplusplus commented on Jan 29, 2016

    @stephenplusplus
    Contributor

    Using this as an example: https://github.com/GoogleCloudPlatform/gcloud-node/blob/30817fcc10195da0136baefeb38b225986fb1c7e/lib/storage/index.js#L87-L90

    if (!(this instanceof Storage)) {
      options = util.normalizeArguments(this, options);
      return new Storage(options);
    }

    Why do we only normalize if it's not an instance of Storage?

  9. stephenplusplus commented on Jan 29, 2016

    @stephenplusplus
    Contributor
  10. callmehiphop commented on Jan 29, 2016

    @callmehiphop
    Contributor

    Why do we only normalize if it's not an instance of Storage?

    If the current context is not an instance of a service (e.g. Storage), that implies that the context is probably gcloud, which is where we store global config.

  11. stephenplusplus commented on Jan 29, 2016

    @stephenplusplus
    Contributor

    So I'm wondering, since we only normalize under that condition, how do we move that logic to the Service constructor?

  12. callmehiphop commented on Jan 29, 2016

    @callmehiphop
    Contributor

    So I'm wondering, since we only normalize under that condition, how do we move that logic to the Service constructor?

    Ahh right, not sure if there's a way around that.. we might have to re-think things a little bit if we want to try and refactor that logic into the Service class.

  13. 3 remaining items

  14. added a commit that references this issue on Jan 28, 2026
  15. added a commit that references this issue on Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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