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

feat(bigquery): check json_rows arg type in insert_rows_json() #10162

Merged
merged 2 commits into from
Jan 17, 2020

Conversation

IlyaFaer
Copy link

Fixes #10132

@IlyaFaer IlyaFaer added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: bigquery Issues related to the BigQuery API. labels Jan 16, 2020
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jan 16, 2020
Copy link
Author

@IlyaFaer IlyaFaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tswast, maybe we should do the same thing for insert_rows()? The situation in it is very close to insert_rows_json():

def insert_rows(self, table, rows, selected_fields=None, **kwargs):
"""Insert rows into a table via the streaming API.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll
Args:
table (Union[ \
google.cloud.bigquery.table.Table, \
google.cloud.bigquery.table.TableReference, \
str, \
]):
The destination table for the row data, or a reference to it.
rows (Union[Sequence[Tuple], Sequence[dict]]):
Row data to be inserted. If a list of tuples is given, each
tuple should contain data for each schema field on the
current table and in the same order as the schema fields. If
a list of dictionaries is given, the keys must include all
required fields in the schema. Keys which do not correspond
to a field in the schema are ignored.

@@ -2506,6 +2506,8 @@ def insert_rows_json(
identifies the row, and the "errors" key contains a list of
the mappings describing one or more problems with the row.
"""
if not isinstance(json_rows, collections_abc.Sequence):
raise TypeError("json_rows argument should be a sequence of dicts")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it with isinstance(). It'll be True for sequences, but not for dicts:

Безымянный

@IlyaFaer IlyaFaer marked this pull request as ready for review January 16, 2020 13:46
@IlyaFaer IlyaFaer requested a review from a team January 16, 2020 13:46
@tswast
Copy link
Contributor

tswast commented Jan 17, 2020

maybe we should do the same thing for insert_rows()? The situation in it is very close to insert_rows_json():

Yes, that's a good idea.

@tswast tswast merged commit ae54dc3 into googleapis:master Jan 17, 2020
This was referenced Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BigQuery: raise a TypeError if a dictionary is passed to insert_rows_json
3 participants