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

bigquery.table.Table.upload_from_file() doesn't check the initial request response status #2132

Closed
theacodes opened this issue Aug 18, 2016 · 2 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@theacodes
Copy link
Contributor

theacodes commented Aug 18, 2016

If you try to add data to a table from a file without a schema:

bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset(dataset_name)
table = dataset.table(table_name)

    with open(source_file_name, 'rb') as source_file:
        job = table.upload_from_file(
            source_file, source_format='text/csv', rewind=True)

job.begin()

This will fail with an opaque error:

Traceback (most recent call last):
  File "load_data_from_file.py", line 74, in <module>
    args.source_file_anme)
  File "load_data_from_file.py", line 40, in load_data_from_gcs
    source_file, source_format='text/csv', rewind=True)
  File "/Users/jonwayne/workspace/python-docs-samples/bigquery/cloud-client/env/lib/python3.4/site-packages/gcloud/bigquery/table.py", line 913, in upload_from_file
    return client.job_from_resource(json.loads(response_content))
  File "/Users/jonwayne/workspace/python-docs-samples/bigquery/cloud-client/env/lib/python3.4/site-packages/gcloud/bigquery/client.py", line 119, in job_from_resource
    config = resource['configuration']
KeyError: 'configuration'

Inspection of the response from the initial upload request reveals the problem:

status: 400
body:
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Empty schema specified for the load job. Please specify a schema that describes the data being loaded.",
...

It seems we should check the response before constructing the job.

@theacodes theacodes added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: bigquery Issues related to the BigQuery API. labels Aug 18, 2016
@theacodes
Copy link
Contributor Author

Weirdly enough you can upload data to a table from GCS without needing a schema.

@theacodes theacodes changed the title bigquery.table.Table.upload_from_file() doens't check the initial request response status bigquery.table.Table.upload_from_file() doesn't check the initial request response status Aug 18, 2016
@tseaver tseaver self-assigned this Sep 20, 2016
@tseaver
Copy link
Contributor

tseaver commented Sep 20, 2016

Issue is similar to #1712 for Storage: look at #1717 for the fix there.

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. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants