Title: `project` kwarg ignored when `from_service_account_json` is used · Issue #108 · googleapis/python-cloud-core · GitHub
Open Graph Title: `project` kwarg ignored when `from_service_account_json` is used · Issue #108 · googleapis/python-cloud-core
X Title: `project` kwarg ignored when `from_service_account_json` is used · Issue #108 · googleapis/python-cloud-core
Description: Copied from an internal bug 191836777 with some examples tweaked to have generic names. @tseaver Could you take a look? When creating a bq client with explicit project name, for example ('my-project') and explicit gcp json key ('other-pr...
Open Graph Description: Copied from an internal bug 191836777 with some examples tweaked to have generic names. @tseaver Could you take a look? When creating a bq client with explicit project name, for example ('my-projec...
X Description: Copied from an internal bug 191836777 with some examples tweaked to have generic names. @tseaver Could you take a look? When creating a bq client with explicit project name, for example ('my-pr...
Opengraph URL: https://github.com/googleapis/python-cloud-core/issues/108
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`project` kwarg ignored when `from_service_account_json` is used","articleBody":"Copied from an internal bug 191836777 with some examples tweaked to have generic names.\r\n\r\n@tseaver Could you take a look?\r\n\r\n---\r\nWhen creating a bq client with explicit project name, for example ('my-project') and explicit gcp json key ('other-project.json'). The connection context is set to the project specified in the json (other-project) and not the explicit one given as an argument (my-project).\r\n\r\nCreated a service account in project \"pynix-cloud\"\r\n\r\nCreate a test script as below:\r\n\r\n```py\r\nfrom google.cloud import bigquery\r\nproject1 = \"pynix-cloud\"\r\nproject2 = \"fileshare-project\"\r\n\r\nprint('Creating client1 for project: %s' %project1)\r\nclient1 = bigquery.Client.from_service_account_json('owner-sa.json', project=project1)\r\nprint(\"Getting the project context for client1: %s\" %client1.project)\r\nprint(\" \")\r\nprint(\"Creating client2 for project: %s\" %project2)\r\nclient2 = bigquery.Client.from_service_account_json('owner-sa.json', project=project2)\r\nprint(\"Getting the project context for client2: %s\" %client2.project)\r\n```\r\n\r\nRunning this scripts outputs as below:\r\n\r\n```\r\nCreating client1 for project: pynix-cloud\r\nGetting the project context for client1: pynix-cloud\r\n \r\nCreating client2 for project: fileshare-project\r\nGetting the project context for client2: pynix-cloud\r\n```\r\n\r\nHowever, the intended behaviour should be that the context for client2 should be the project \"fileshare-project\" as that is the project been passed explicitly as argument.\r\n\r\nDebugging on the issue and going over the code I have following observations:\r\n\r\nThe bigquery client class has a call to super class \"ClientWithProject\" as per [1]. The class \"ClientWithProject\" is imported in the same code and is part of the core package [2].\r\n\r\nI read thru the code for class \"ClientWithProject\" and stopped at this line [3]. I suspected there to be missing something so I tired to play around the same. What I did was I modified the line in [3]\r\n\r\n\r\nfrom :\r\n```\r\nreturn cls.from_service_account_info(credentials_info)\r\n```\r\nto:\r\n```py\r\nreturn cls.from_service_account_info(credentials_info,**kwargs)\r\n```\r\nmind the keywords been passed as arguments. Post this I again ran my test script and I got the expected results, ie the context was from the project been passed as argument:\r\n```\r\nCreating client1 for project: pynix-cloud\r\nGetting the project context for client1: pynix-cloud\r\n \r\nCreating client2 for project: fileshare-project\r\nGetting the project context for client2: fileshare-project\r\n```\r\nAs this is something seen broken in v1.7 for core component. Looking at the release note for core 1.7 [4] there was a change where in we added 'Client.from_service_account_info' factory [5]. this function is indeed the one been called in [3]. If we refer to the code from 1.4.1 this was not implemented there [6]. Also when the customer downgraded the core component to 1.4 it started working as expected.\r\n\r\nSo my best take is that may be this is a bug and not the intended behaviour for v1.7. We might have missed passing the keywords as args so when at line [7] the keyword dict is empty and we tend to fetch the project from the service account json file itself.\r\n\r\nKindly let me know if this observation is correct and if we can do the required changes to get this working again in case the issue reported is not an indented behaviour in v1.7.\r\n\r\n[1] https://github.com/googleapis/python-bigquery/blob/18bb443c7acd0a75dcb57d9aebe38b2d734ff8c7/google/cloud/bigquery/client.py#L199\r\n\r\n[2] from google.cloud.client import ClientWithProject\r\n\r\n[3] https://github.com/googleapis/python-cloud-core/blob/1d3e273292e0c3eae2b150c9a05e610eb4ade78d/google/cloud/client.py#L109\r\n\r\n[4] https://github.com/googleapis/python-cloud-core/tree/master/google/cloud\r\n\r\n[5] https://github.com/googleapis/python-cloud-core/pull/54\r\n\r\n[6] https://github.com/googleapis/python-cloud-core/blob/release-v1.4.1/google/cloud/client.py\r\n\r\n[7] https://github.com/googleapis/python-cloud-core/blob/1d3e273292e0c3eae2b150c9a05e610eb4ade78d/google/cloud/client.py#L78\r\n\r\nGitHub repository: https://github.com/googleapis/python-cloud-core","author":{"url":"https://github.com/busunkim96","@type":"Person","name":"busunkim96"},"datePublished":"2021-06-23T16:49:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/108/python-cloud-core/issues/108"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cb1873b3-2764-f4e7-0583-77fc53fda69e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BAE4:2C03D:8246093:B6560CC:6A5006C5 |
| html-safe-nonce | d6a45dcc25bb1f5079886b013c59fff913780b23e8279983fee995f56d4b9972 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUU0OjJDMDNEOjgyNDYwOTM6QjY1NjBDQzo2QTUwMDZDNSIsInZpc2l0b3JfaWQiOiIxODg2NjU2OTU1OTgxNzYwMTk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e8baacc13dd1df8269c812d0ae6a59ccbc7bb467b66649d4184d5b633467ef85 |
| hovercard-subject-tag | issue:928457153 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-cloud-core/108/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c74c3aba9f9d0a9e634b211cf7cccebb9d9ee8e201b3401754bb7db5608dddd/googleapis/python-cloud-core/issues/108 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c74c3aba9f9d0a9e634b211cf7cccebb9d9ee8e201b3401754bb7db5608dddd/googleapis/python-cloud-core/issues/108 |
| og:image:alt | Copied from an internal bug 191836777 with some examples tweaked to have generic names. @tseaver Could you take a look? When creating a bq client with explicit project name, for example ('my-projec... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | busunkim96 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 56eec25a3430492dd6ec2a480eb33256a0da5192d5714b0db4f5ab5f33203d94 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-cloud-core git https://github.com/googleapis/python-cloud-core.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992462 |
| octolytics-dimension-repository_nwo | googleapis/python-cloud-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992462 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-cloud-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 93a615b89b7dcbdb6b678f4772931ecc28ada82a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width