Skip to content

Commit 281e3ff

Browse files
fix: return 409 error in createJob() for dry run (#1003)
* fix: return 409 error in createJob() dry run * fix test * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update README.md * Update README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e0007cb commit 281e3ff

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/bigquery.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,9 @@ export class BigQuery extends common.Service {
15181518
callback?: JobCallback
15191519
): void | Promise<JobResponse> {
15201520
const JOB_ID_PROVIDED = typeof options.jobId !== 'undefined';
1521+
const DRY_RUN = options.configuration?.dryRun
1522+
? options.configuration.dryRun
1523+
: false;
15211524

15221525
const reqOpts = Object.assign({}, options);
15231526
let jobId = JOB_ID_PROVIDED ? reqOpts.jobId : uuid.v4();
@@ -1558,7 +1561,8 @@ export class BigQuery extends common.Service {
15581561
if (err) {
15591562
if (
15601563
(err as common.ApiError).code === ALREADY_EXISTS_CODE &&
1561-
!JOB_ID_PROVIDED
1564+
!JOB_ID_PROVIDED &&
1565+
!DRY_RUN
15621566
) {
15631567
// The last insert attempt flaked, but the API still processed the
15641568
// request and created the job. Because of our "autoRetry" feature,

test/bigquery.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,20 @@ describe('BigQuery', () => {
17491749
});
17501750
});
17511751

1752+
it('should return 409 if dryRun is true', done => {
1753+
const error = new util.ApiError('Error.');
1754+
error.code = 409;
1755+
1756+
bq.request = (reqOpts: DecorateRequestOptions, callback: Function) => {
1757+
callback(error);
1758+
};
1759+
1760+
bq.createJob({configuration: {dryRun: true}}, (err: Error) => {
1761+
assert.strictEqual(err, error);
1762+
done();
1763+
});
1764+
});
1765+
17521766
it('should return any status errors', done => {
17531767
const errors = [{reason: 'notFound'}];
17541768
const response = extend(true, {}, RESPONSE, {

0 commit comments

Comments
 (0)