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 client not getting ProjectID from env #1092

Closed
thesandlord opened this issue Jan 27, 2016 · 13 comments
Closed

Datastore client not getting ProjectID from env #1092

thesandlord opened this issue Jan 27, 2016 · 13 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@thesandlord
Copy link

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});
@stephenplusplus
Copy link
Contributor

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

@stephenplusplus stephenplusplus added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: datastore Issues related to the Datastore API. labels Jan 27, 2016
@thesandlord
Copy link
Author

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

@stephenplusplus
Copy link
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?

@callmehiphop
Copy link
Contributor

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

@stephenplusplus
Copy link
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)
.

@callmehiphop
Copy link
Contributor

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

@stephenplusplus
Copy link
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?

@stephenplusplus
Copy link
Contributor

Related: #845 (comment)

@callmehiphop
Copy link
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.

@stephenplusplus
Copy link
Contributor

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

@callmehiphop
Copy link
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.

@stephenplusplus
Copy link
Contributor

Should we just leave it?

@callmehiphop
Copy link
Contributor

Might be a good idea for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants