Skip to content

Commit

Permalink
fix(pg): Return patched promise instead of original (#1470)
Browse files Browse the repository at this point in the history
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes #1319.
  • Loading branch information
punya authored Aug 29, 2022
1 parent ed422ed commit e79407e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/plugins/plugin-pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class PostgresPatchUtility {
promise: Promise<pg_7.QueryResult>,
span: Span
): Promise<pg_7.QueryResult> {
return (promise = promise.then(
return promise.then(
res => {
this.maybePopulateLabelsFromOutputs(span, null, res);
span.endSpan();
Expand All @@ -170,7 +170,7 @@ class PostgresPatchUtility {
span.endSpan();
throw err;
}
));
);
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ const plugin: Plugin = [
// Unlike in pg 6, the returned value can't be both a Promise and
// a Submittable. So we don't run the risk of double-patching
// here.
pgPatch.patchPromise(pgQuery, span);
pgQuery = pgPatch.patchPromise(pgQuery, span);
}
}
return pgQuery;
Expand Down

0 comments on commit e79407e

Please sign in to comment.