fix(cli): Apply .env to os.environ so in-process SDK clients see project env vars#10038
Draft
edgarrmondragon wants to merge 1 commit into
Draft
fix(cli): Apply .env to os.environ so in-process SDK clients see project env vars#10038edgarrmondragon wants to merge 1 commit into
.env to os.environ so in-process SDK clients see project env vars#10038edgarrmondragon wants to merge 1 commit into
Conversation
…ect env vars Variables set in a project's `.env` (e.g. `AWS_PROFILE`, `AZURE_TENANT_ID`, `GOOGLE_APPLICATION_CREDENTIALS`) were invisible to cloud SDK clients (boto3, azure-storage-blob, google-cloud-storage) running inside the Meltano process. Meltano read `.env` via `dotenv_values()` into an internal dict that is passed to plugin *subprocesses*, but never injected into `os.environ`. SDK clients read `os.environ` directly, so they never saw these values. Fix: call `load_dotenv(override=False)` in the CLI entry point right after the project is located, so any `.env` variable that is not already set in the shell gets injected into `os.environ`. Shell variables always take precedence (`override=False`), preserving the existing priority order. To keep Meltano's own settings-store source attribution correct, `EnvStoreManager` now subtracts `project.dotenv_env` keys from the env dict it exposes. This ensures that a variable in `.env` is still reported as coming from `.env` (not "the environment") in `meltano config get`, and that `AutoStoreManager` write decisions are unaffected. Closes #10037 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
✅ Deploy Preview for meltano canceled.
|
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures project .env variables are both available to in-process SDK clients via os.environ and still correctly attributed to .env in Meltano’s settings layer, while fixing a NoResultFound import. Sequence diagram for CLI loading .env into os.environsequenceDiagram
actor User
participant MeltanoCLI as MeltanoCLI
participant Project as Project
participant DotEnv as load_dotenv
User ->> MeltanoCLI: cli(env_file)
MeltanoCLI ->> Project: find(dotenv_file)
Project -->> MeltanoCLI: project
MeltanoCLI ->> DotEnv: load_dotenv(dotenv_path=project.dotenv, override=False)
MeltanoCLI ->> MeltanoCLI: setup_logging(project)
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
.env to os.environ so in-process SDK clients see project env vars
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10038 +/- ##
==========================================
- Coverage 96.74% 96.68% -0.06%
==========================================
Files 286 286
Lines 25460 25463 +3
Branches 1451 1451
==========================================
- Hits 24631 24619 -12
- Misses 667 683 +16
+ Partials 162 161 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Variables set in a project's
.env(e.g.AWS_PROFILE,AZURE_TENANT_ID,GOOGLE_APPLICATION_CREDENTIALS) were invisible to cloud SDK clients (boto3, azure-storage-blob, google-cloud-storage) running inside the Meltano process.Meltano reads
.envviadotenv_values()into an internal dict that is passed to plugin subprocesses as part of their environment, but the values were never injected intoos.environ. Cloud SDK clients reados.environdirectly, so they never saw those values. The only workaround was to set the variable in the shell before invoking Meltano (e.g.AWS_PROFILE=arch-prod meltano state get ...).Fix:
Call
load_dotenv(override=False)in the CLI entry point right after the project is located. This injects any.envvariable not already set in the shell intoos.environ, so SDK clients pick it up. Shell variables always take precedence (override=False), preserving the existing priority order.EnvStoreManager.envnow subtractsproject.dotenv_envkeys before returning. This ensures that a variable in.envis still reported as coming from.env(not "the environment") inmeltano config get, and thatAutoStoreManagerwrite-store decisions are unaffected.Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Sonnet 4.6 following the agentic coding guidelines
Related Issues
.envvalues not visible to in-process SDK clients (e.g.AWS_PROFILEfor S3 state backend) #10037Summary by Sourcery
Load project .env variables into the Meltano CLI process environment while preserving correct configuration source reporting between environment and .env stores.
Bug Fixes:
Enhancements: