From 87dd1f3f4c92d0f540e5c00faece435e71abb982 Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Sun, 28 Aug 2022 21:17:06 -0400 Subject: [PATCH] fix: Return patched promise instead of original This ensures that asynchronous work done by patching gets awaited properly. In particular, it prevents unhandled promise rejections. Fixes #1319. --- src/plugins/plugin-pg.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/plugin-pg.ts b/src/plugins/plugin-pg.ts index 801605283..548dd4353 100644 --- a/src/plugins/plugin-pg.ts +++ b/src/plugins/plugin-pg.ts @@ -159,7 +159,7 @@ class PostgresPatchUtility { promise: Promise, span: Span ): Promise { - return (promise = promise.then( + return promise.then( res => { this.maybePopulateLabelsFromOutputs(span, null, res); span.endSpan(); @@ -170,7 +170,7 @@ class PostgresPatchUtility { span.endSpan(); throw err; } - )); + ); } } @@ -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;