OpenJobDescription / openjd-sessions-for-python

Provides a Python library that can be used to build a runtime that is able to run Jobs in a Session as defined by Open Job Description.
https://github.com/OpenJobDescription/openjd-specifications/wiki
Apache License 2.0
10 stars 12 forks source link

Bug: Duplicate Environment Variables on Windows #157

Closed edwards-aws closed 2 months ago

edwards-aws commented 2 months ago

Expected Behaviour

Environment variables on Windows are case insensitive. This means that if an environment variable is set via the openjd_env: key=value mechanism it would be expected that it overrides any existing environment variables regardless of casing. For example if there already existed an environment variable Test=test and OpenJD finds openjd_env: TEST=test2, it would be expected that only TEST=test2 would be found in the environment.

Current Behaviour

If there already exists an environment variable, say Test=test, and OpenJD finds openjd_env: TEST=test2. Two environment variables with the same name, but with different casing, will be stored. When queried Windows will choose the first one that was written, in this case it would use the value test instead of test2 as expected.

Reproduction Steps

Set an environment variable to something with lower case letters in the key, like set Test=test. Then print out that same environment in all caps like python -c "print('openjd_env: TEST=test2')". Next call set, observe that both environment variables are present when only one should be.

Code Snippet

Seems to be related to these lines https://github.com/OpenJobDescription/openjd-sessions-for-python/blob/mainline/src/openjd/sessions/_session.py#L138 and https://github.com/OpenJobDescription/openjd-sessions-for-python/blob/mainline/src/openjd/sessions/_win32/_popen_as_user.py#L152

The keys here should be all changed to uppercase to avoid case conflicting issues.