jason810496 commented on code in PR #71144:
URL: https://github.com/apache/airflow/pull/71144#discussion_r3793877748
##########
ts-sdk/src/cli/pack.ts:
##########
@@ -143,20 +143,52 @@ function readBundleManifest(bundlePath: string):
BundleManifest {
throw new Error(`Bundle produced no ${AIRFLOW_METADATA_FLAG} output`);
}
- let manifest: BundleManifest;
+ let parsed: unknown;
try {
- manifest = JSON.parse(line.slice(AIRFLOW_METADATA_SENTINEL.length)) as
BundleManifest;
+ parsed = JSON.parse(line.slice(AIRFLOW_METADATA_SENTINEL.length));
} catch (error) {
throw new Error(`Bundle produced invalid ${AIRFLOW_METADATA_FLAG} output:
${String(error)}`, {
cause: error,
});
}
- if (!manifest.supervisor_schema_version || !manifest.dags || typeof
manifest.dags !== "object") {
+ if (!isBundleManifest(parsed)) {
throw new Error(`Bundle produced incomplete ${AIRFLOW_METADATA_FLAG}
output`);
}
+ const manifest = parsed;
+ // The line is whatever the bundle printed and nothing downstream
re-validates
+ // it, so check each Dag entry down to the task-id element.
+ for (const [dagId, dag] of Object.entries(manifest.dags)) {
+ if (dag == null || !isDagIdList(dag.tasks)) {
+ throw new Error(
+ `Bundle produced ${AIRFLOW_METADATA_FLAG} output with a malformed
entry for Dag "${dagId}"`,
+ );
+ }
+ }
return manifest;
}
+// The document is checked before anything is read off it: JSON.parse also
yields
+// null and primitives, and `null.supervisor_schema_version` would surface as a
+// raw TypeError rather than a report about the bundle.
+function isBundleManifest(value: unknown): value is BundleManifest {
+ if (typeof value !== "object" || value === null || Array.isArray(value))
return false;
+ const { supervisor_schema_version: version, dags } = value as
Partial<BundleManifest>;
+ return (
+ // Rendered into the manifest verbatim, where the schema requires a
non-empty
+ // string, so a truthy number or boolean would travel to Airflow as-is.
+ typeof version === "string" &&
+ version.length > 0 &&
Review Comment:
Yes, we will validate against a regex in
https://github.com/apache/airflow/pull/70993.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]