-
Notifications
You must be signed in to change notification settings - Fork 20
Fix EnvConfig to read from system environment variables #371
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?
Conversation
Previously, when `override_env_vars` was not provided, the code passed
an empty hash (`override_env_vars || {}`) to the Rust bridge. This
caused the core library to use that empty hash as the env var source
instead of reading from the actual system environment.
The fix conditionally omits the argument when nil, allowing the Rust
bridge to treat it as optional and fall back to `std::env::var()`
for system environment variable lookups.
| ) | ||
| path, data = EnvConfig._source_to_path_and_data(config_source) | ||
|
|
||
| raw_profile = Internal::Bridge::EnvConfig.load_client_connect_config( |
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.
Can you just leave the existing code and just remove || {}?
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.
I initially did this, I thought Rust's Option<HashMap> would allow for nil values from Ruby, but scan_args tries to convert nil to HashMap.
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.
You could just spread the optional arg: *([override_env_vars] unless override_env_vars.nil?)
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.
ooh nice - done
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.
I would rather not splat at this point. I think you should make every argument required from the Rust side. It's internal code, we should not add optional fields on ourselves. Can move to structs if needed since param list is growing large.
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.
Changed from splatting to explicit conditional. Making the change Rust side is prudent but I'd prefer not to delay the fix.
| end | ||
| end | ||
|
|
||
| def with_system_env_vars(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.
Need to add a decl to the .rbs:
def with_system_env_vars: [T] (Hash[String, String] env_vars) { () -> T } -> T
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.
added
Previously, when
override_env_varswas not provided, the code passed an empty hash (override_env_vars || {}) to the Rust bridge. This caused the core library to use that empty hash as the env var source instead of reading from the actual system environment.The fix conditionally omits the argument when nil, allowing the Rust bridge to treat it as optional and fall back to
std::env::var()for system environment variable lookups.Why?
Bug fix
Added test