Skip to content

Commit 60cbed8

Browse files
authored
Revert PR #1527: remove one-time defaultEnvManager User-settings migration
1 parent 7e3f696 commit 60cbed8

4 files changed

Lines changed: 5 additions & 349 deletions

File tree

src/common/telemetry/constants.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,7 @@ export enum EventNames {
198198
*/
199199
PET_RESOLVE = 'PET.RESOLVE',
200200
/**
201-
* Telemetry event for the one-time migration that removes a stale
202-
* `python-envs.defaultEnvManager: system` value from User (global) settings.
203-
* Fires only on the activation when the migration actually runs (not on subsequent runs).
204-
* Properties:
205-
* - outcome: 'removed' (was set to system, all user-scope slots cleared)
206-
* | 'partial' (cleared current context's slot but another user-scope slot still has it; will retry)
207-
* | 'not_set' (no user-scope slot of system found, nothing to do)
208-
* | 'failed' (attempted removal threw)
209-
* - errorType: string (only when outcome === 'failed')
210-
*/
211-
MIGRATION_SYSTEM_ENV_MANAGER = 'MIGRATION.SYSTEM_ENV_MANAGER',
212-
/**
213-
* Telemetry event fired once per session, per URI, the first time a `.py`
201+
* Telemetry event fired once per session, per URI, the first time a `.py`
214202
* file with a valid PEP 723 `# /// script` block is observed by the lazy
215203
* detector. Used to size the population of users who actually see inline
216204
* script files — the denominator for the "view vs edit" question.
@@ -695,17 +683,6 @@ export interface IEventNamePropertyMapping {
695683
petCommitSha?: string;
696684
};
697685

698-
/* __GDPR__
699-
"migration.system_env_manager": {
700-
"outcome": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "eleanorjboyd" },
701-
"errorType": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "eleanorjboyd" }
702-
}
703-
*/
704-
[EventNames.MIGRATION_SYSTEM_ENV_MANAGER]: {
705-
outcome: 'removed' | 'partial' | 'not_set' | 'failed';
706-
errorType?: string;
707-
};
708-
709686
/* __GDPR__
710687
"inlineScript.detected": {
711688
"trigger": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "owner": "StellaHuang95" },

src/extension.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import {
7373
import { PythonProjectManagerImpl } from './features/projectManager';
7474
import { getPythonApi, setPythonApi } from './features/pythonApi';
7575
import { registerCompletionProvider } from './features/settings/settingCompletions';
76-
import { migrateGlobalDefaultEnvManagerSetting } from './features/settings/settingHelpers';
7776
import { setActivateMenuButtonContext } from './features/terminal/activateMenuButton';
7877
import { normalizeShellPath } from './features/terminal/shells/common/shellUtils';
7978
import {
@@ -166,15 +165,6 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
166165
// Setup the persistent state for the extension.
167166
setPersistentState(context);
168167

169-
// One-time migration: remove `system` defaultEnvManager from User settings if a previous
170-
// version wrote it there (bug #1468). Awaited so the migration deterministically affects
171-
// initial environment selection on the very first activation after upgrade.
172-
try {
173-
await migrateGlobalDefaultEnvManagerSetting();
174-
} catch (err) {
175-
traceError(`[migration] migrateGlobalDefaultEnvManagerSetting threw: ${err}`);
176-
}
177-
178168
const statusBar = new PythonStatusBarImpl();
179169
context.subscriptions.push(statusBar);
180170

src/features/settings/settingHelpers.ts

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import * as path from 'path';
22
import { ConfigurationScope, ConfigurationTarget, Uri, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
33
import { PythonProject } from '../../api';
4-
import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID, SYSTEM_MANAGER_ID } from '../../common/constants';
4+
import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants';
55
import { traceError, traceInfo, traceVerbose, traceWarn } from '../../common/logging';
6-
import { getGlobalPersistentState } from '../../common/persistentState';
76
import { normalizePath } from '../../common/utils/pathUtils';
8-
import { EventNames } from '../../common/telemetry/constants';
9-
import { sendTelemetryEvent } from '../../common/telemetry/sender';
107
import * as workspaceApis from '../../common/workspace.apis';
118
import { PythonProjectManager, PythonProjectSettings } from '../../internal.api';
129

@@ -584,93 +581,3 @@ export function getSettingUserScope<T>(section: string, key: string): T | undefi
584581
}
585582
return undefined;
586583
}
587-
588-
const MIGRATION_KEY = 'globalSettingsMigration.systemEnvManagerRemoved';
589-
590-
/**
591-
* Returns true if any user-scope slot of the inspection result equals `value`.
592-
* For window-scoped settings VS Code may populate `globalRemoteValue` and/or
593-
* `globalLocalValue` in addition to `globalValue` depending on context.
594-
*/
595-
function userScopeHasValue(inspect: { globalValue?: string } | undefined, value: string): boolean {
596-
if (!inspect) {
597-
return false;
598-
}
599-
const record = inspect as Record<string, unknown>;
600-
if (record.globalRemoteValue === value) {
601-
return true;
602-
}
603-
if (record.globalLocalValue === value) {
604-
return true;
605-
}
606-
if (inspect.globalValue === value) {
607-
return true;
608-
}
609-
return false;
610-
}
611-
612-
/**
613-
* One-time migration: removes `defaultEnvManager` from User (global) settings if it was
614-
* set to `system` by the extension. This was an unintentional side effect of a bug where
615-
* the extension wrote to User scope when no workspace was open. Having `system` at the
616-
* User level causes all workspaces to ignore local .venv environments.
617-
*
618-
* Because `python-envs.defaultEnvManager` is a window-scoped setting, the stale value can
619-
* land in any of `globalValue`, `globalLocalValue`, or `globalRemoteValue` depending on
620-
* which context (local vs remote) hit the bug. We check all three, attempt removal via
621-
* `ConfigurationTarget.Global` (which clears the slot for the current context), then
622-
* re-inspect. If any user-scope slot still holds the stale value we do NOT mark the
623-
* migration complete, so a future activation in the other context can finish the job.
624-
*
625-
* See: https://github.com/microsoft/vscode-python-environments/issues/1468
626-
*/
627-
export async function migrateGlobalDefaultEnvManagerSetting(): Promise<void> {
628-
const state = await getGlobalPersistentState();
629-
const alreadyMigrated = await state.get<boolean>(MIGRATION_KEY);
630-
if (alreadyMigrated) {
631-
return;
632-
}
633-
634-
const config = workspaceApis.getConfiguration('python-envs', undefined);
635-
const inspect = config.inspect<string>('defaultEnvManager');
636-
637-
if (!userScopeHasValue(inspect, SYSTEM_MANAGER_ID)) {
638-
sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { outcome: 'not_set' });
639-
await state.set(MIGRATION_KEY, true);
640-
return;
641-
}
642-
643-
try {
644-
await config.update('defaultEnvManager', undefined, ConfigurationTarget.Global);
645-
} catch (err) {
646-
// Don't mark migration done; we'll retry on a future activation.
647-
traceWarn(
648-
`[migration] Failed to remove 'python-envs.defaultEnvManager: ${SYSTEM_MANAGER_ID}' from User settings: ${err}`,
649-
);
650-
sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, {
651-
outcome: 'failed',
652-
errorType: err instanceof Error ? err.name : typeof err,
653-
});
654-
return;
655-
}
656-
657-
// Re-inspect: `update(Global)` only clears the current context's slot. If another
658-
// context's slot (local vs remote) still holds the stale value, leave the flag unset
659-
// so the next activation in that context can clear it.
660-
const after = config.inspect<string>('defaultEnvManager');
661-
if (userScopeHasValue(after, SYSTEM_MANAGER_ID)) {
662-
traceInfo(
663-
`[migration] Partially removed 'python-envs.defaultEnvManager: ${SYSTEM_MANAGER_ID}' from User settings; ` +
664-
`another context still has it set. Will retry on next activation.`,
665-
);
666-
sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { outcome: 'partial' });
667-
return;
668-
}
669-
670-
traceInfo(
671-
`[migration] Removed 'python-envs.defaultEnvManager: ${SYSTEM_MANAGER_ID}' from User settings ` +
672-
`(was set unintentionally by a previous version). See https://github.com/microsoft/vscode-python-environments/issues/1468`,
673-
);
674-
sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { outcome: 'removed' });
675-
await state.set(MIGRATION_KEY, true);
676-
}

0 commit comments

Comments
 (0)