-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
GbqConnector should be able to fetch default credentials on Google Compute Engine #13608
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
Conversation
in the future pls don't open new PR's for the same issue, just push to the old one. it causes extra work. |
Current coverage is 85.25% (diff: 3.57%)@@ master #13608 diff @@
==========================================
Files 139 139
Lines 50143 50272 +129
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 42777 42857 +80
- Misses 7366 7415 +49
Partials 0 0
|
@jreback Got it. Apologies for that! This was my first contribution - the last PR got a bit messy. Will be careful next time. Thanks! |
no prob. It just keeps a better chain to have a single PR. |
Coverage gives wrong percentage if imports are missing
@jreback the new method that I added has some googleapiclient imports which cause the test to not completely capture the lines of codes. Can someone please have a look and close or suggest further actions. Thanks, |
return credentials | ||
|
||
@staticmethod | ||
def get_application_default_credentials(project_id): # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to follow the existing pattern, why is this a staticmethod? that's non-pythonic.
nested try/except is a no-no
just call your routine, if the default oauth imports raise you don't care, the user will get an import error.
only the addl imports (for getting default credientials) need to be caught (and return None).
you can
@jreback I will incorporate all the changes you suggested. Thank you for your time! p.s. things like nested try/catch; staticmethod; etc. I implemented these to trick codecov and nosetests to cover/pass test for the new method. I will revert these changes. |
@jreback incorporated the suggested changes. Thanks! :) |
Hi @jreback I was wondering - did you have a look at my last changes? Is the pull request eligible to be merged? Thanks! :) |
needs tests |
@jreback I have written this test "test_get_application_default_credentials_should_not_throw_error" which should call (cover) the new method I've added. The "test environment" is probably skipping (TestGBQConnectorIntegration.setUp) this test because "project_id" is not set. I am guessing - even if I add more tests they will be skipped. As you can see from the coverage report - not even the first line of the method is covered - If I am not understanding this correctly - could you please guide me how to solve this. Thank you for your time! |
@@ -217,6 +218,12 @@ def test_should_be_able_to_get_results_from_query(self): | |||
schema, pages = self.sut.run_query('SELECT 1') | |||
self.assertTrue(pages is not None) | |||
|
|||
def test_get_application_default_credentials_should_not_throw_error(self): | |||
from oauth2client.client import GoogleCredentials |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you need to do skipping based on resource availablity, see the other tests.
Hi @jreback, do you think the pull request is fine now. The second test (test_get_application_default_credentials_returns_credentials) will only be executed (not skipped) if a google account is authenticated (for gcloud) on the environment. |
@@ -80,6 +80,7 @@ def _test_imports(): | |||
from apiclient.discovery import build # noqa | |||
from apiclient.errors import HttpError # noqa | |||
|
|||
from oauth2client.client import GoogleCredentials # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this inside of try
so tests pass with oauth2client==1.2
@mhaseebtariq 👍 Lightning fast! |
All tests pass locally. I also found that Pandas GBQ integration now works seamlessly in Google Datalab with this PR. Note: This only works if user is already logged into Google Datalab. One observation that I noticed is that Google Datalab usually prompts the user to sign in if
|
I receive the following error with
|
Additional output from local test
|
return None | ||
|
||
# Check if the application has rights to the BigQuery project | ||
bigquery_service = build('bigquery', 'v2', credentials=credentials) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be in try
for compatibility with google-api-python-client==1.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parthea I've changed the call to the "build" method - should work for both api versions now.
Looks good to me. I tested 3 different configurations. Test scenario 1:
Test scenario 2:
Test scenario 3:
|
Hi @jreback I was wondering when will this pull request be closed - all tests have passed now. Thanks! |
@@ -4475,6 +4475,15 @@ Additional information on service accounts can be found | |||
|
|||
You will need to install an additional dependency: `oauth2client <https://github.com/google/oauth2client>`__. | |||
|
|||
.. versionadded:: 0.19.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be below the change
This is not even running thru travis at all. pls add the deps that are required to one of the |
@jreback on: "...add deps that are required to one of the The dependent library is already mentioned in
This change requires google-api-python-client==1.5 though. What do you suggest I should do then - change the version numbers for this library in these files? |
@mhaseebtariq so the import tests should then work on 3.4 build (which has latest version), and skip on 2.7. pls show the results from travis here |
@jreback Even with the correct library version, the test will still be skipped because - The user should be logged in to Google Cloud in the environment the tests are being run. partheas has already successfully tested the functionality on the correct environment. |
Yes. All gbq tests pass.
I've confirmed both This feature isn't supported if |
@mhaseebtariq Try adding your forked repository (mhaseebtariq/pandas) to https://travis-ci.org/. Its super easy. Register at https://travis-ci.org/ , then add your forked repository. This will allow you to retry builds to see whether the error is reproducible. |
Now the tests are passing! |
thanks! |
git diff upstream/master | flake8 --diff