From c039ffe81ec25be0d80c87cd758ac3340fae94b2 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 18 May 2022 23:28:02 +0200 Subject: [PATCH] fix: language field broke flow too --- .../20220518211432_make_lang_nullable.down.sql | 1 + .../20220518211432_make_lang_nullable.up.sql | 6 ++++++ backend/src/jobs.rs | 6 +++--- backend/src/worker.rs | 18 ++++++++++++++---- 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 backend/migrations/20220518211432_make_lang_nullable.down.sql create mode 100644 backend/migrations/20220518211432_make_lang_nullable.up.sql diff --git a/backend/migrations/20220518211432_make_lang_nullable.down.sql b/backend/migrations/20220518211432_make_lang_nullable.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20220518211432_make_lang_nullable.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20220518211432_make_lang_nullable.up.sql b/backend/migrations/20220518211432_make_lang_nullable.up.sql new file mode 100644 index 0000000000..9d3c0b1c86 --- /dev/null +++ b/backend/migrations/20220518211432_make_lang_nullable.up.sql @@ -0,0 +1,6 @@ +-- Add up migration script here +ALTER TABLE queue +ALTER COLUMN language DROP NOT NULL; + +ALTER TABLE completed_job +ALTER COLUMN language DROP NOT NULL; diff --git a/backend/src/jobs.rs b/backend/src/jobs.rs index 79230cc8aa..6079c10641 100644 --- a/backend/src/jobs.rs +++ b/backend/src/jobs.rs @@ -84,7 +84,7 @@ pub struct QueuedJob { pub flow_status: Option, pub raw_flow: Option, pub is_flow_step: bool, - pub language: ScriptLang, + pub language: Option, } #[derive(Debug, sqlx::FromRow, Serialize)] @@ -113,7 +113,7 @@ struct CompletedJob { flow_status: Option, raw_flow: Option, is_flow_step: bool, - language: ScriptLang, + language: Option, } #[derive(Deserialize, Clone, Copy)] @@ -864,7 +864,7 @@ struct UnifiedJob { permissioned_as: String, flow_status: Option, is_flow_step: bool, - language: ScriptLang, + language: Option, } impl From for Job { diff --git a/backend/src/worker.rs b/backend/src/worker.rs index 65d117637a..3fc6581430 100644 --- a/backend/src/worker.rs +++ b/backend/src/worker.rs @@ -347,14 +347,19 @@ async fn handle_job( let (inner_content, requirements_o, language) = if matches!(job.job_kind, JobKind::Preview) { let code = (job.raw_code.as_ref().unwrap_or(&"no raw code".to_owned())).to_owned(); - let reqs = if job.language == ScriptLang::Python3 { + let reqs = if job + .language + .as_ref() + .map(|x| matches!(x, ScriptLang::Python3)) + .unwrap_or(false) + { Some(parser::parse_python_imports(&code)?.join("\n")) } else { None }; (code, reqs, job.language.to_owned()) } else { - sqlx::query_as::<_, (String, Option, ScriptLang)>("SELECT content, lock, language FROM script WHERE hash = $1 AND (workspace_id = $2 OR workspace_id = 'starter')") + sqlx::query_as::<_, (String, Option, Option)>("SELECT content, lock, language FROM script WHERE hash = $1 AND (workspace_id = $2 OR workspace_id = 'starter')") .bind(&job.script_hash.unwrap_or(ScriptHash(0)).0) .bind(&job.workspace_id) .fetch_optional(db) @@ -363,7 +368,12 @@ async fn handle_job( }; match language { - ScriptLang::Python3 => { + None => { + return Err(Error::ExecutionErr( + "Require language to be not null".to_string(), + ))?; + } + Some(ScriptLang::Python3) => { let requirements = requirements_o .ok_or_else(|| Error::InternalErr(format!("lockfile missing")))?; @@ -494,7 +504,7 @@ print(res_json) status = handle_child(job, db, &mut logs, &mut last_line, timeout, child).await; } } - ScriptLang::Deno => { + Some(ScriptLang::Deno) => { logs.push_str("\n\n--- DENO CODE EXECUTION ---\n"); set_logs(logs, job.id, db).await;