GeezerVison is showing github.com — Calling 'job.begin' on job returned from 'Table.upload_from_file' raises a 400 · Issue #2133 · googleapis/google-cloud-python
Calling 'job.begin' on job returned from 'Table.upload_from_file' raises a 400 #2133DescriptionTrying to load data into bigquery with upload_from_file returns a 400.
Sample code:
def load_data_from_file(dataset_name, table_name, source_file_name):
bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset(dataset_name)
table = dataset.table(table_name)
# Reload the table to get the schema.
table.reload()
with open(source_file_name, 'rb') as source_file:
# This example uses CSV, but you can use other formats.
# See https://cloud.google.com/bigquery/loading-data
job = table.upload_from_file(
source_file, source_format='text/csv')
job.begin()
wait_for_job(job)
print('Loaded {} rows into {}:{}.'.format(
job.output_rows, dataset_name, table_name))
Error:
Traceback (most recent call last):
File "load_data_from_file.py", line 77, in <module>
args.source_file_anme)
File "load_data_from_file.py", line 45, in load_data_from_file
job.begin()
File "/Users/jonwayne/workspace/python-docs-samples/bigquery/cloud-client/env/lib/python3.4/site-packages/gcloud/bigquery/job.py", line 364, in begin
method='POST', path=path, data=self._build_resource())
File "/Users/jonwayne/workspace/python-docs-samples/bigquery/cloud-client/env/lib/python3.4/site-packages/gcloud/connection.py", line 347, in api_request
error_info=method + ' ' + url)
gcloud.exceptions.BadRequest: 400 Load configuration must specify at least one source URI (POST https://www.googleapis.com/bigquery/v2/projects/python-docs-samples-tests/jobs)
Activitymatheuspatury commented on Sep 13, 2016 Any updates on this issue? My project is stuck because of it... jgeewax commented on Sep 13, 2016 tseaver commented on Sep 13, 2016 There is a workaround: first upload the file to Storage, and then load the table from there. E.g., see this system test.
I will look into reproducing the issue with a new system test. changed the title [-]bigquery.table.Table.upload_from_file fails with 400[/-] [+]Calling 'job.begin' on job returned from Table.upload_from_file[/+] on Sep 14, 2016changed the title [-]Calling 'job.begin' on job returned from Table.upload_from_file[/-] [+]Calling 'job.begin' on job returned from 'Table.upload_from_file' raises a 400[/+] on Sep 14, 2016tseaver commented on Sep 14, 2016 @jonparrott, @matheuspatury Note that it is an error to call job.begin(), because the job returned from table.upload_from_file is a) already started, and b) lacks information needed to start (the error it reports). #2313 shows that the job completes fine without that call. theacodes commented on Sep 14, 2016 ContributorAuthor More actions added and removed type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on Sep 14, 2016tseaver commented on Sep 14, 2016 In this mode, we start by uploading a file: the back-end spools the uploaded file off somewhere in secret, and has begun to process it before ever returning to the client. Other jobs are created locally on the client first. Given how the back-end works, the only way to be "consistent" would be to remove this feature, and require that users upload files to Storage before loading them.
We could raise a more informative error from Job.begin if we could detect this case (self.state != None would do it), or we could make it a no-op instead. theacodes commented on Sep 14, 2016 ContributorAuthor More actions Weird.
An informative error from begin would be okay with me, as long as there isn't strong feelings that it should no-op.
It would also be nice to update the docstring to indicate that the job is already started. added a commit that references this issue on Sep 15, 2016This issue will close once commit d861610 is merged into the 'main' branch.d861610 Etiennepi commented on Nov 30, 2016 tseaver commented on Nov 30, 2016 theacodes commented on Nov 30, 2016 ContributorAuthor More actions Weird, that snippet is tested. Did we make begin() idempotent? theacodes commented on Nov 30, 2016 ContributorAuthor More actions Nevermind, I see. I had the test marked as xfail. Fixing now. Thanks!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|