Skip to content

BigQuery: raise a TypeError if a dictionary is passed to insert_rows_json #10132

@tswast

Description

@tswast

Is your feature request related to a problem? Please describe.

If I want to only insert a single row at a time into a table, it's easy to accidentally try something like:

json_row = {"col1": "hello", "col2": "world"}
errors = client.insert_rows_json(
    table,
    json_row
)

This results in a 400 BadRequest error from the API, because it expects a list of rows, not a single row.

Describe the solution you'd like

It's difficult to debug this situation from the API response, so it'd be better if we raised a client-side error for passing in the wrong type for json_rows.

Describe alternatives you've considered

Leave as-is and request a better server-side message. This may be difficult to do, as the error happens at a level above BigQuery, which translates JSON to Protobuf for internal use.

Additional context

This issue was encountered by a customer engineer, and it took me a bit of debugging to figure out the actual issue. I expect other customers will encounter this problem as well.

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions