Skip to content

Commit 576b99f

Browse files
committed
fix for async modules
1 parent e5e4fcf commit 576b99f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,14 @@ export class DataSchemaCompiler {
353353
exports[file.fileName] = obj;
354354
},
355355
asyncModule: (fn) => {
356-
asyncModules.push(fn);
356+
const file = ctxFileStorage.getStore();
357+
if (!file) {
358+
throw new Error('No file stored in context');
359+
}
360+
// We need to run async module code in the context of the original data model file
361+
// where it was defined. So we pass the same file to the async context.
362+
// @see https://nodejs.org/api/async_context.html#class-asynclocalstorage
363+
asyncModules.push(async () => ctxFileStorage.run(file, () => fn()));
357364
},
358365
require: (extensionName: string) => {
359366
const file = ctxFileStorage.getStore();

0 commit comments

Comments
 (0)