mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-06 00:02:13 +00:00
fix: track relative imports in python and ts even if lockfile is provided
This commit is contained in:
@@ -40,6 +40,7 @@ use std::{
|
||||
};
|
||||
use windmill_audit::audit_ee::audit_log;
|
||||
use windmill_audit::ActionKind;
|
||||
use windmill_worker::process_relative_imports;
|
||||
|
||||
use windmill_common::error::to_anyhow;
|
||||
|
||||
@@ -894,6 +895,25 @@ async fn create_script_internal<'c>(
|
||||
.await?;
|
||||
Ok((hash, new_tx))
|
||||
} else {
|
||||
if let Err(e) = process_relative_imports(
|
||||
&db,
|
||||
None,
|
||||
None,
|
||||
&w_id,
|
||||
&ns.path,
|
||||
p_path_opt.clone(),
|
||||
ns.deployment_message.clone(),
|
||||
&ns.content,
|
||||
&Some(ns.language.clone()),
|
||||
&authed.email,
|
||||
&authed.username,
|
||||
&permissioned_as,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::error!(%e, "error processing relative imports");
|
||||
}
|
||||
|
||||
handle_deployment_metadata(
|
||||
&authed.email,
|
||||
&authed.username,
|
||||
|
||||
@@ -49,6 +49,8 @@ mod worker_flow;
|
||||
mod worker_lockfiles;
|
||||
mod worker_utils;
|
||||
|
||||
pub use worker_lockfiles::process_relative_imports;
|
||||
|
||||
pub use worker::*;
|
||||
|
||||
pub use result_processor::handle_job_error;
|
||||
|
||||
@@ -364,44 +364,21 @@ pub async fn handle_dependency_job(
|
||||
tracing::error!(%e, "error handling deployment metadata");
|
||||
}
|
||||
|
||||
let relative_imports =
|
||||
extract_relative_imports(&script_data.code, script_path, &job.script_lang);
|
||||
if let Some(relative_imports) = relative_imports {
|
||||
update_script_dependency_map(
|
||||
&job.id,
|
||||
db,
|
||||
w_id,
|
||||
&parent_path,
|
||||
script_path,
|
||||
relative_imports,
|
||||
)
|
||||
.await?;
|
||||
let already_visited = job
|
||||
.args
|
||||
.as_ref()
|
||||
.map(|x| {
|
||||
x.get("already_visited")
|
||||
.map(|v| serde_json::from_str::<Vec<String>>(v.get()).ok())
|
||||
.flatten()
|
||||
})
|
||||
.flatten()
|
||||
.unwrap_or_default();
|
||||
if let Err(e) = trigger_dependents_to_recompute_dependencies(
|
||||
w_id,
|
||||
script_path,
|
||||
deployment_message,
|
||||
parent_path,
|
||||
&job.permissioned_as_email,
|
||||
&job.created_by,
|
||||
&job.permissioned_as,
|
||||
db,
|
||||
already_visited,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::error!(%e, "error triggering dependents to recompute dependencies");
|
||||
}
|
||||
}
|
||||
process_relative_imports(
|
||||
db,
|
||||
Some(job.id),
|
||||
job.args.as_ref(),
|
||||
&job.workspace_id,
|
||||
script_path,
|
||||
parent_path,
|
||||
deployment_message,
|
||||
&script_data.code,
|
||||
&job.script_lang,
|
||||
&job.permissioned_as_email,
|
||||
&job.created_by,
|
||||
&job.permissioned_as,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(to_raw_value_owned(
|
||||
json!({ "status": "Successful lock file generation", "lock": content }),
|
||||
@@ -439,6 +416,58 @@ fn remove_ansi_codes(s: &str) -> String {
|
||||
ANSI_REGEX.replace_all(s, "").to_string()
|
||||
}
|
||||
|
||||
pub async fn process_relative_imports(
|
||||
db: &sqlx::Pool<sqlx::Postgres>,
|
||||
job_id: Option<Uuid>,
|
||||
args: Option<&Json<HashMap<String, Box<RawValue>>>>,
|
||||
w_id: &str,
|
||||
script_path: &str,
|
||||
parent_path: Option<String>,
|
||||
deployment_message: Option<String>,
|
||||
code: &str,
|
||||
script_lang: &Option<ScriptLang>,
|
||||
permissioned_as_email: &str,
|
||||
created_by: &str,
|
||||
permissioned_as: &str,
|
||||
) -> error::Result<()> {
|
||||
let relative_imports = extract_relative_imports(&code, script_path, script_lang);
|
||||
if let Some(relative_imports) = relative_imports {
|
||||
update_script_dependency_map(
|
||||
&job_id.unwrap_or_else(|| Uuid::nil()),
|
||||
db,
|
||||
w_id,
|
||||
&parent_path,
|
||||
script_path,
|
||||
relative_imports,
|
||||
)
|
||||
.await?;
|
||||
let already_visited = args
|
||||
.map(|x| {
|
||||
x.get("already_visited")
|
||||
.map(|v| serde_json::from_str::<Vec<String>>(v.get()).ok())
|
||||
.flatten()
|
||||
})
|
||||
.flatten()
|
||||
.unwrap_or_default();
|
||||
if let Err(e) = trigger_dependents_to_recompute_dependencies(
|
||||
w_id,
|
||||
script_path,
|
||||
deployment_message,
|
||||
parent_path,
|
||||
permissioned_as_email,
|
||||
created_by,
|
||||
permissioned_as,
|
||||
db,
|
||||
already_visited,
|
||||
)
|
||||
.await
|
||||
{
|
||||
tracing::error!(%e, "error triggering dependents to recompute dependencies");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn trigger_dependents_to_recompute_dependencies(
|
||||
w_id: &str,
|
||||
script_path: &str,
|
||||
|
||||
Reference in New Issue
Block a user