From f10f61f1d65579f719c25b7d1ceccd02986ae31e Mon Sep 17 00:00:00 2001 From: c0b <14798161+c0b@users.noreply.github.com> Date: Thu, 9 Nov 2017 10:16:50 -0500 Subject: [PATCH] =?UTF-8?q?use=20jobReference.jobId=20instead,=20to=20not?= =?UTF-8?q?=20include=20the=20"project-id:"=20pref=E2=80=A6=20(#2737)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * use jobReference.jobId instead, to not include the "project-id:" prefix for Job constructor current code use the job.id from metadata in jobs.list api response to construct a Job; however it has the full format of "project-id:jobid-........." the constructed Job from this full id format can't be used for further acesss, like job.get job.getQueryResults server side will return an "Invalid job ID" error; see this fixes #2736 the metadata response has jobReference.jobId is exactly needed here; { kind: 'bigquery#job', etag: '"cX5UmbB_R-S07ii743IKGH9YCYM/4xT3EKx31LcQTmnaqUafpQ2RHqU"', id: 'project-id:job_D3tTAICe8jSlPuOw8CSvLEKs7-0C', selfLink: 'https://www.googleapis.com/bigquery/v2/projects//jobs/job_D3tTAICe8jSlPuOw8CSvLEKs7-0C', jobReference: { projectId: '', jobId: 'job_D3tTAICe8jSlPuOw8CSvLEKs7-0C' }, --- packages/bigquery/src/index.js | 2 +- packages/bigquery/test/index.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/bigquery/src/index.js b/packages/bigquery/src/index.js index 0ae231e0e66..50fa39091dc 100644 --- a/packages/bigquery/src/index.js +++ b/packages/bigquery/src/index.js @@ -806,7 +806,7 @@ BigQuery.prototype.getJobs = function(options, callback) { } var jobs = (resp.jobs || []).map(function(jobObject) { - var job = that.job(jobObject.id); + var job = that.job(jobObject.jobReference.jobId); job.metadata = jobObject; return job; }); diff --git a/packages/bigquery/test/index.js b/packages/bigquery/test/index.js index 4583e0cbc67..5209372e8e2 100644 --- a/packages/bigquery/test/index.js +++ b/packages/bigquery/test/index.js @@ -1048,7 +1048,16 @@ describe('BigQuery', function() { it('should return Job objects', function(done) { bq.request = function(reqOpts, callback) { - callback(null, { jobs: [{ id: JOB_ID }] }); + callback(null, { + jobs: [ + { + id: JOB_ID, + jobReference: { + jobId: JOB_ID + } + } + ] + }); }; bq.getJobs(function(err, jobs) { @@ -1059,7 +1068,16 @@ describe('BigQuery', function() { }); it('should return apiResponse', function(done) { - var resp = { jobs: [{ id: JOB_ID }] }; + var resp = { + jobs: [ + { + id: JOB_ID, + jobReference: { + jobId: JOB_ID + } + } + ] + }; bq.request = function(reqOpts, callback) { callback(null, resp); @@ -1073,7 +1091,16 @@ describe('BigQuery', function() { }); it('should assign metadata to the Job objects', function(done) { - var jobObjects = [{ a: 'b', c: 'd', id: JOB_ID }]; + var jobObjects = [ + { + a: 'b', + c: 'd', + id: JOB_ID, + jobReference: { + jobId: JOB_ID + } + } + ]; bq.request = function(reqOpts, callback) { callback(null, { jobs: jobObjects });