Skip to content

Commit 32f5510

Browse files
author
Kartik Raj
authored
Do not remove envs which are provided by the consumer (microsoft#20424)
For microsoft#20292 We currently remove environments from cache which aren't part of the latest discovery run. This is not correct as consumers can still select envs not reported by discovery run, which we shouldn't remove.
1 parent 65cf0fb commit 32f5510

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
9999
if (envs && isCompleteList) {
100100
/**
101101
* Only consider a cached env to be valid if it's relevant. That means:
102-
* * It is either reported in the latest complete refresh for this session.
103-
* * Or it is relevant for some other workspace folder which is not opened currently.
102+
* * It is relevant for some other workspace folder which is not opened currently.
103+
* * It is either reported in the latest complete discovery for this session.
104+
* * It is provided by the consumer themselves.
104105
*/
105106
if (cachedEnv.searchLocation) {
106107
return true;
107108
}
108109
if (envs.some((env) => cachedEnv.id === env.id)) {
109110
return true;
110111
}
112+
if (Array.from(this.validatedEnvs.keys()).some((envId) => cachedEnv.id === envId)) {
113+
// These envs are provided by the consumer themselves, consider them valid.
114+
return true;
115+
}
111116
} else {
112117
return true;
113118
}
@@ -141,7 +146,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
141146
public addEnv(env: PythonEnvInfo, hasLatestInfo?: boolean): void {
142147
const found = this.envs.find((e) => areSameEnv(e, env));
143148
if (hasLatestInfo) {
144-
traceVerbose(`Adding env to cache ${env.id}`);
149+
traceVerbose(`Flushing env to cache ${env.id}`);
145150
this.validatedEnvs.add(env.id!);
146151
this.flush(env).ignoreErrors(); // If we have latest info, flush it so it can be saved.
147152
}

0 commit comments

Comments
 (0)