Skip to content

Fix empty string environment variable support#1788

Open
terryfinn wants to merge 3 commits intobasecamp:mainfrom
powerhome:fix-empty-env-vars
Open

Fix empty string environment variable support#1788
terryfinn wants to merge 3 commits intobasecamp:mainfrom
powerhome:fix-empty-env-vars

Conversation

@terryfinn
Copy link
Copy Markdown

@terryfinn terryfinn commented Feb 23, 2026

Fix: Preserve empty string environment variables

What changed and why

This PR fixes a bug where empty string environment variables are silently ignored. The fix modifies lib/kamal/utils.rb to explicitly preserve empty strings when building Docker arguments.

The Problem

Applications often need to distinguish between undefined and empty environment variables:

# Example: Queue worker configuration
queues = ENV.fetch("QUEUES", "*").split(",")
# Undefined => "*" (all queues)
# "" => no queues (maintenance mode)
# "critical" => specific queue

With QUEUES: "" in deploy.yml, Kamal currently omits the variable entirely, causing the application to incorrectly use the default value.

The Solution

# lib/kamal/utils.rb line 11
- if value.present?
+ if value.present? || value == ""

This minimal change ensures empty strings are passed as --env VAR="" to Docker.

@terryfinn terryfinn force-pushed the fix-empty-env-vars branch 4 times, most recently from f702b97 to 1eafe9b Compare February 24, 2026 04:40
Empty strings in env configuration were filtered out by present?
check. Now explicitly preserves empty strings as valid environment
values with proper quoting (QUEUES="") for clarity and consistency.

This allows distinguishing between undefined and empty environment
variables, which is important for applications using three-state
environment logic.
@terryfinn terryfinn force-pushed the fix-empty-env-vars branch from 1eafe9b to 4b39933 Compare March 12, 2026 18:52
@terryfinn terryfinn marked this pull request as ready for review March 12, 2026 18:53
Copilot AI review requested due to automatic review settings March 12, 2026 18:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes handling of environment variables configured with empty-string values so they are not silently omitted when generating Docker CLI arguments, allowing apps to distinguish between “unset” and “set to empty”.

Changes:

  • Preserve empty-string values in Kamal::Utils.argumentize so env vars like EMPTY: "" are emitted as --env EMPTY="".
  • Ensure shell-escaping returns a proper quoted empty string for "" values.
  • Add test coverage for empty-string env values in both low-level utils and configuration env parsing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/kamal/utils.rb Preserves "" values during argument building and emits a properly quoted empty string during shell escaping.
test/utils_test.rb Adds a unit test asserting argumentize includes empty-string env vars as VAR="".
test/configuration/env_test.rb Adds a configuration test ensuring clear env values preserve empty strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Fix white space

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 12, 2026 18:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants