From 49aa55425776384b59ec83f4dba8316f598db1ff Mon Sep 17 00:00:00 2001 From: Ionite Date: Thu, 11 Apr 2024 15:22:01 -0400 Subject: [PATCH] Fix settings env var conflict --- .../Models/Settings/Settings.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/StabilityMatrix.Core/Models/Settings/Settings.cs b/StabilityMatrix.Core/Models/Settings/Settings.cs index 01e22fd2..ff65f104 100644 --- a/StabilityMatrix.Core/Models/Settings/Settings.cs +++ b/StabilityMatrix.Core/Models/Settings/Settings.cs @@ -118,10 +118,22 @@ public class Settings public Dictionary? UserEnvironmentVariables { get; set; } [JsonIgnore] - public IReadOnlyDictionary EnvironmentVariables => - DefaultEnvironmentVariables - .Concat(UserEnvironmentVariables ?? []) - .ToDictionary(x => x.Key, x => x.Value); + public IReadOnlyDictionary EnvironmentVariables + { + get + { + if (UserEnvironmentVariables is null || UserEnvironmentVariables.Count == 0) + { + return DefaultEnvironmentVariables; + } + + return DefaultEnvironmentVariables + .Concat(UserEnvironmentVariables) + .GroupBy(pair => pair.Key) + // User variables override default variables with the same key + .ToDictionary(grouping => grouping.Key, grouping => grouping.Last().Value); + } + } public HashSet? InstalledModelHashes { get; set; } = new();