-
Notifications
You must be signed in to change notification settings - Fork 817
feat: env var in flow #6852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: env var in flow #6852
Conversation
Claude finished @dieriba's task —— View job Code Review Complete ✅I've completed a comprehensive review of PR #6852: feat: env var in flow OverviewThis PR adds support for flow-level environment variables, allowing users to define key-value pairs at the flow level that can be referenced in flow steps via Summary of ChangesBackend (Rust):
Frontend (Svelte):
Code Quality Assessment✅ Strengths
|
/// resumes should be in order of timestamp ascending, so that more recent are at the end | ||
#[instrument(level = "trace", skip_all)] | ||
async fn transform_input( | ||
env_args: Option<&HashMap<String, String>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition: The env_args
parameter properly passes flow environment variables to the transform function. However, consider adding a comment explaining that these are flow-level environment variables (not system env vars) for clarity.
env_args: Option<&HashMap<String, String>>, | |
async fn transform_input( | |
// Flow-level environment variables defined in the flow configuration | |
env_args: Option<&HashMap<String, String>>, |
env.insert("resume".to_string(), resume); | ||
env.insert("resumes".to_string(), resumes); | ||
env.insert("approvers".to_string(), approvers); | ||
if let Some(env_args) = env_args { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential issue: Consider using serde_json::to_value()
instead of to_raw_value()
for better type safety and error handling. The current implementation might panic on serialization failure.
if let Some(env_args) = env_args { | |
if let Some(env_args) = env_args { | |
match serde_json::to_value(env_args) { | |
Ok(val) => { | |
if let Ok(raw) = serde_json::value::to_raw_value(&val) { | |
env.insert("env".to_string(), Arc::new(raw)); | |
} | |
} | |
Err(e) => { | |
tracing::warn!("Failed to serialize env_args: {}", e); | |
} | |
} | |
} |
flowStore.val.value.env_vars = {} | ||
} | ||
let envVars = $derived(flowStore.val.value.env_vars || {}) | ||
let envEntries = $derived( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Svelte 5 best practice: Good use of $derived
for reactive state! However, consider memoizing the envEntries
computation since Object.entries()
creates a new array on every access. This could cause unnecessary re-renders.
let envEntries = $derived( | |
let envEntries = $derived.by(() => | |
Object.entries(envVars).map(([key, value], index) => ({ id: `${key}_${index}`, key, value })) | |
) |
} | ||
} | ||
function updateEnvKey(oldKey: string, newKey: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential bug: This function mutates the store but doesn't validate the new key. If newKey
already exists or contains invalid characters, it could cause issues. Add validation:
function updateEnvKey(oldKey: string, newKey: string) { | |
function updateEnvKey(oldKey: string, newKey: string) { | |
if (flowStore.val.value.env_vars && oldKey !== newKey && newKey.trim() !== '') { | |
// Validate key format (alphanumeric, underscore, starts with letter) | |
if (!/^[A-Z_][A-Z0-9_]*$/i.test(newKey)) { | |
// Show error to user | |
return | |
} | |
// Check for duplicate | |
if (newKey in flowStore.val.value.env_vars) { | |
// Show error to user | |
return | |
} | |
const value = flowStore.val.value.env_vars[oldKey] | |
delete flowStore.val.value.env_vars[oldKey] | |
flowStore.val.value.env_vars[newKey] = value | |
flowStore.val = flowStore.val | |
} | |
} |
<input | ||
type="text" | ||
value={entry.key} | ||
onblur={(e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Svelte 5 compliance issue: You're using onblur
with a function, but in Svelte 5 you should use the direct event attribute syntax. However, the more critical issue is that this loses the old key value if the user enters an invalid or duplicate key. Consider using a controlled input pattern with temporary state.
export let allowCopy = false | ||
export let alwaysOn = false | ||
export let previousId: string | undefined = undefined | ||
export let env: Record<string, string> | undefined = undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition: The env
prop is properly passed through and made available in the property picker. This provides good UX for discovering available environment variables.
{/if} | ||
{#if env && Object.keys(env).length > 0 && (!filterActive || $inputMatches?.some((match) => match.word === 'env'))} | ||
<div class="overflow-y-auto pb-2"> | ||
<span class="font-normal text-xs text-secondary">Flow Variables:</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: The label "Flow Variables" might be confusing since the platform also has "Variables" as a separate concept. Consider using "Flow Environment Variables" or "Flow Env Vars" for clarity.
backend/windmill-common/src/flows.rs
Outdated
pub chat_input_enabled: Option<bool>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[serde(default)] | ||
pub env_vars: Option<HashMap<String, String>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good implementation: The env_vars
field is properly added to the FlowValue
struct with appropriate serialization attributes. The Option<HashMap<String, String>>
type is correct for optional key-value pairs.
openflow.openapi.yaml
Outdated
type: string | ||
cache_ttl: | ||
type: number | ||
env_vars: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good documentation: The OpenAPI spec is properly updated to reflect the new env_vars
field. This ensures API documentation stays in sync with the code.
Deploying windmill with
|
Latest commit: |
baaf3c4
|
Status: | ✅ Deploy successful! |
Preview URL: | https://e390c93f.windmill.pages.dev |
Branch Preview URL: | https://dieri-env-var-in-flow.windmill.pages.dev |
No description provided.