Closed AlesCUMSI closed 3 weeks ago
Hi @AlesCUMSI,
you are totally right this is the right solution and although I was applying this in other software I am developing, I forgot to add the override=True for the beacon2-ri-api. In the last PR I have made, #364 you will see this fixed.
I am very thankful to you and those were very much appreciated contributions, so thanks,
Oriol
Description: When loading environment variables from multiple .env files in sequence using the load_dotenv() function, the variables from one file are not properly overwritten by subsequent .env files. This can lead to incorrect configurations being used if multiple .env files contain overlapping environment variables. From https://pypi.org/project/python-dotenv/: "_By default, loaddotenv doesn't override existing environment variables."
Location: File: permissions/auth.py Function: get_user_info()
Steps to Reproduce: Place multiple .env files in the /beacon/permissions/idp_providers/ directory, each containing an ISSUER variable with different values. Call the get_user_info() function with an access token whose iss field matches the ISSUER value in the second .env file. Observe that the environment variables from the first .env file are used, even when they should have been overwritten by the second file. Expected Behavior: Environment variables from the latest .env file should overwrite those from earlier files when load_dotenv() is called in a loop.
Actual Behavior: The environment variables from the first .env file persist and are not overwritten by subsequent files.
Suggested Fix: Use load_dotenv(env_filename, override=True) in the loop to ensure that environment variables from each .env file properly overwrite the previous ones.