Skip to content

Commit

Permalink
use jobReference.jobId instead, to not include the "project-id:" pref…
Browse files Browse the repository at this point in the history
…ix 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/<project-id>/jobs/job_D3tTAICe8jSlPuOw8CSvLEKs7-0C',
      jobReference:
       { projectId: '<project-id>',
         jobId: 'job_D3tTAICe8jSlPuOw8CSvLEKs7-0C' },
  • Loading branch information
c0b committed Nov 9, 2017
1 parent eccb085 commit ef54121
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/bigquery/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
9 changes: 6 additions & 3 deletions packages/bigquery/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,8 @@ 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) {
Expand All @@ -1059,7 +1060,8 @@ 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);
Expand All @@ -1073,7 +1075,8 @@ 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 });
Expand Down

0 comments on commit ef54121

Please sign in to comment.