Title: DatabaseAdmin: on Duplicate name in Schema, gRPC FailedPrecondition status code is not handled and sent back as None · Issue #38 · googleapis/python-spanner · GitHub
Open Graph Title: DatabaseAdmin: on Duplicate name in Schema, gRPC FailedPrecondition status code is not handled and sent back as None · Issue #38 · googleapis/python-spanner
X Title: DatabaseAdmin: on Duplicate name in Schema, gRPC FailedPrecondition status code is not handled and sent back as None · Issue #38 · googleapis/python-spanner
Description: If I have a table that already exists and try to create the same table, this package errors but its error code is None yet its message is Duplicate name in schema: . Reproduction from google.cloud import spanner_v1 as spanner def main():...
Open Graph Description: If I have a table that already exists and try to create the same table, this package errors but its error code is None yet its message is Duplicate name in schema: . Reproduction from google.cloud ...
X Description: If I have a table that already exists and try to create the same table, this package errors but its error code is None yet its message is Duplicate name in schema: . Reproduction from google.cloud ...
Opengraph URL: https://github.com/googleapis/python-spanner/issues/38
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DatabaseAdmin: on Duplicate name in Schema, gRPC FailedPrecondition status code is not handled and sent back as None","articleBody":"If I have a table that already exists and try to create the same table, this package errors but its error code is None yet its message is `Duplicate name in schema: `.\r\n\r\n### Reproduction\r\n```python\r\nfrom google.cloud import spanner_v1 as spanner\r\n\r\ndef main():\r\n db = spanner.Client().instance('django-tests').database('db1')\r\n lro = db.update_ddl(['CREATE TABLE foo (id INT64) PRIMARY KEY(id)'])\r\n\r\n try:\r\n result = lro.result()\r\n except Exception as e:\r\n print('\\033[31mCode: %s gRPC_StatusCode: %s Message: %s\\033[00m' % \r\n (e.code, e.grpc_status_code, e.message))\r\n raise e\r\n else:\r\n print(result)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n```\r\nwhich unfortunately prints out\r\n```shell\r\nCode: None gRPC_StatusCode: None Message: Duplicate name in schema: foo.\r\nTraceback (most recent call last):\r\n File \"duplicate_table_v1.py\", line 18, in \u003cmodule\u003e\r\n main()\r\n File \"duplicate_table_v1.py\", line 12, in main\r\n raise e\r\n File \"duplicate_table_v1.py\", line 8, in main\r\n result = lro.result()\r\n File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/google/api_core/future/polling.py\", line 127, in result\r\n raise self._exception\r\ngoogle.api_core.exceptions.GoogleAPICallError: None Duplicate name in schema: foo.\r\n```\r\n\r\nThis bug presents an inconsistency in the error handling because we get an error with a `None` status code and `None` gRPC status code, yet it has a message.\r\n\r\n### Comparison with Go\r\nI can confirm that Cloud Spanner actually sends back the status code because the Go result actually has the status code, with this reproduction and by investigation the responses sent by the Spanner server\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"context\"\r\n\r\n\tdbadmin \"cloud.google.com/go/spanner/admin/database/apiv1\"\r\n\tdbspb \"google.golang.org/genproto/googleapis/spanner/admin/database/v1\"\r\n)\r\n\r\nfunc main() {\r\n\tctx := context.Background()\r\n\tadminClient, err := dbadmin.NewDatabaseAdminClient(ctx)\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\tddlReq := \u0026dbspb.UpdateDatabaseDdlRequest{\r\n\t\tDatabase: \"projects/orijtech-161805/instances/django-tests/databases/db1\",\r\n\t\tStatements: []string{\r\n\t\t\t\"CREATE TABLE foo (id INT64) PRIMARY KEY(id)\",\r\n\t\t},\r\n\t}\r\n\tlro, err := adminClient.UpdateDatabaseDdl(ctx, ddlReq)\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\tif err := lro.Wait(ctx); err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n}\r\n```\r\nand prints out\r\n```shell\r\nSleeping for 947.779411ms\r\npanic: rpc error: code = FailedPrecondition desc = Duplicate name in schema: foo.\r\n\r\ngoroutine 1 [running]:\r\nmain.main()\r\n\t/Users/emmanuelodeke/Desktop/spanner-orm-trials/duplicate_table.go:27 +0x1db\r\nexit status 2\r\n```\r\n\r\n### Postulation\r\nI think that the result of waiting on the long running operation isn't being properly used to retrieve the status code.\r\n\r\n/cc @larkee @skuruppu, and for an FYI @bvandiver @timgraham","author":{"url":"https://github.com/odeke-em","@type":"Person","name":"odeke-em"},"datePublished":"2020-03-16T02:38:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/38/python-spanner/issues/38"}
| 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:8f1eda07-a5df-2dec-d488-9f816d2b0a43 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CB6:2C07F4:F283FB:151CB1D:6A4DF0EF |
| html-safe-nonce | a0a6e3cd6e45c93ee95c463c21359816e50c781afcfd0d99c6192477ceab1651 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0I2OjJDMDdGNDpGMjgzRkI6MTUxQ0IxRDo2QTRERjBFRiIsInZpc2l0b3JfaWQiOiI1MDc1NDM3ODg0MjUwMzg2NjcxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a7dfb064793162de971f07c08a811eca810eb8244a3b6000f5ed5b79e9c7f8be |
| hovercard-subject-tag | issue:581949648 |
| 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-spanner/38/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b4773e22fef3e969ec5a22901c1de8b727aaa409ccd02f4c2bff1fdbdece1826/googleapis/python-spanner/issues/38 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b4773e22fef3e969ec5a22901c1de8b727aaa409ccd02f4c2bff1fdbdece1826/googleapis/python-spanner/issues/38 |
| og:image:alt | If I have a table that already exists and try to create the same table, this package errors but its error code is None yet its message is Duplicate name in schema: . Reproduction from google.cloud ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | odeke-em |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-spanner git https://github.com/googleapis/python-spanner.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992630 |
| octolytics-dimension-repository_nwo | googleapis/python-spanner |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992630 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-spanner |
| 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 | f4bb89367ca678f057d79b1abc45d6675b1bd5b2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width