Title: client.insert_rows should fail when inserting non-existing fields · Issue #151 · googleapis/python-bigquery · GitHub
Open Graph Title: client.insert_rows should fail when inserting non-existing fields · Issue #151 · googleapis/python-bigquery
X Title: client.insert_rows should fail when inserting non-existing fields · Issue #151 · googleapis/python-bigquery
Description: Version google-cloud-bigquery==1.25.0 The client.insert_rows() function doesn't fail when inserting non-existing fields whereas the BigQuery API does fail with a message like { "kind": "bigquery#tableDataInsertAllResponse", "insertErrors...
Open Graph Description: Version google-cloud-bigquery==1.25.0 The client.insert_rows() function doesn't fail when inserting non-existing fields whereas the BigQuery API does fail with a message like { "kind": "bigquery#ta...
X Description: Version google-cloud-bigquery==1.25.0 The client.insert_rows() function doesn't fail when inserting non-existing fields whereas the BigQuery API does fail with a message like { "kind"...
Opengraph URL: https://github.com/googleapis/python-bigquery/issues/151
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"client.insert_rows should fail when inserting non-existing fields","articleBody":"Version\r\n```\r\ngoogle-cloud-bigquery==1.25.0\r\n```\r\n\r\nThe [`client.insert_rows()`](https://github.com/googleapis/python-bigquery/blob/v1.25.0/google/cloud/bigquery/client.py#L2471) function doesn't fail when inserting non-existing fields whereas the BigQuery API does fail with a message like\r\n```\r\n{\r\n \"kind\": \"bigquery#tableDataInsertAllResponse\",\r\n \"insertErrors\": [\r\n {\r\n \"index\": 0,\r\n \"errors\": [\r\n {\r\n \"reason\": \"invalid\",\r\n \"location\": \"zap\",\r\n \"debugInfo\": \"\",\r\n \"message\": \"no such field.\"\r\n }\r\n ]\r\n }\r\n ]\r\n}\r\n```\r\n`insert_rows()` silently drops the additional columns instead.\r\n\r\nThis happens because `insert_rows()` uses [`_record_field_to_json`](https://github.com/googleapis/python-bigquery/blob/3869e34f3eff6fabca21c397e3f1cbc368ec880e/google/cloud/bigquery/_helpers.py#L409) which only iterates over the list of fields that are provided ignoring all the other fields that are part of the data and `insert_rows()` passes the table's schema as list of fields to `_record_field_to_json`.\r\n\r\nThis behavior is opposite to the BigQuery API and means we cannot reliably insert data because we're not made aware of changes to the incoming data because there's no failure.\r\nIMHO this behavior is not correct, I think it would be OK if `selected_fields` was provided but it should not silently use the schema to limit which of the fields of the input data are processed and ignore the rest.\r\nI can image there might be cases where one wants to be lenient/ignore all fields that are not part of table so this behavior might have to be an option, possibly combined with `selected_fields`.\r\n\r\nP.S. By extension this also applies to the [`client.insert_rows_from_dataframe()`](https://github.com/googleapis/python-bigquery/blob/v1.25.0/google/cloud/bigquery/client.py#L2533) function which uses `client.insert_rows()`.\r\n\r\nP.P.S We initially ran into this when using `insert_rows_from_dataframe()` and it was a bit of a search to find where this was going wrong because it's a somewhat indirect chain of `insert_rows_from_dataframe -\u003e insert_rows -\u003e insert_rows_json`.\r\nWhy was this long way chosen/added instead of simply using `insert_rows_json(table, df.to_dict(orient=\"records\"))`? It seems a lot simpler and will probably be the workaround we'll implement for now.","author":{"url":"https://github.com/simonvanderveldt","@type":"Person","name":"simonvanderveldt"},"datePublished":"2020-06-26T14:16:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/151/python-bigquery/issues/151"}
| 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:d1017710-dba0-b9cd-37f6-e4d62507fba0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2BE:3DC5A5:BAB158:106B6B5:6A4E89B3 |
| html-safe-nonce | 88241938eeee72d7b3c38ab55904b5d31b2de9046fc1d3134af07d69741f361d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkJFOjNEQzVBNTpCQUIxNTg6MTA2QjZCNTo2QTRFODlCMyIsInZpc2l0b3JfaWQiOiI2NjUzNDc5MjU0NzI0ODcyNjI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bcc07e857e9ec1a199ce0839baa4dc5c653f09ea4349bb215dbf57f80dec2f51 |
| hovercard-subject-tag | issue:646293928 |
| 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-bigquery/151/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e47b3fae36fb51cd4357e85c743f79ad88a1e70805816f90429553b68e01a09d/googleapis/python-bigquery/issues/151 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e47b3fae36fb51cd4357e85c743f79ad88a1e70805816f90429553b68e01a09d/googleapis/python-bigquery/issues/151 |
| og:image:alt | Version google-cloud-bigquery==1.25.0 The client.insert_rows() function doesn't fail when inserting non-existing fields whereas the BigQuery API does fail with a message like { "kind": "bigquery#ta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | simonvanderveldt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-bigquery git https://github.com/googleapis/python-bigquery.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992475 |
| octolytics-dimension-repository_nwo | googleapis/python-bigquery |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992475 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-bigquery |
| 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 | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width