[bug-fix] Fix reinstall-overwrites-kept-config: preserve config on plain reinstall after --keep-config
Bug fix — reinstall-overwrites-kept-config
Proposed fix for issue #3427, applying the remediation from the bug assessment.
Verdict: Valid · Severity: medium
Summary
When specify extension remove <ext> --keep-config is used, the extension is unregistered but its *-config.yml files survive in the extension directory. A subsequent plain specify extension add <ext> unconditionally deleted that directory before copying the fresh extension in, silently discarding the preserved config. The fix rescues those stranded config files into memory before the rmtree and writes them back after copytree, so user-customized values always win over the packaged defaults.
Changes
| File | Change | Notes |
|---|---|---|
src/specify_cli/extensions/__init__.py |
modified | Before rmtree(dest_dir), collect any *-config.yml / *-config.local.yml files from an unregistered dest_dir into memory; restore them after copytree |
tests/test_extensions.py |
added tests | test_reinstall_after_keep_config_preserves_config and test_reinstall_after_keep_config_preserves_local_config |
Tests Added or Updated
tests/test_extensions.py::TestInstallFromDirectory::test_reinstall_after_keep_config_preserves_config— pins that a customized*-config.ymlsurvives aremove --keep-config→ plain reinstall cycletests/test_extensions.py::TestInstallFromDirectory::test_reinstall_after_keep_config_preserves_local_config— same for*-config.local.ymloverride files
Local Verification
- No project test command could be exercised in this environment (no venv, no pytest available). The logic was verified by code inspection: the fix mirrors the existing backup/restore pattern used by the
--forcereinstall path, applying it to the previously-unhandled "unregistered but config-bearing directory" case.
Deviations from Assessment
None. The implementation follows the preferred remediation exactly as described.
Risks & Review Notes
- Config files are read into memory; these files are typically < 1 KB so there is no memory concern.
- The
not self.registry.is_installed(manifest.id)guard ensures we only rescue configs when the extension is genuinely unregistered, avoiding picking up stale files from a different install. - The write-back happens after
shutil.copytree, so packaged defaults are always superseded by the user's values — no risk of defaults silently winning. install_from_zip()delegates toinstall_from_directory(), so it is covered without additional changes.- No API surface change; all changes are internal to
install_from_directory().
Refs #3427 · cc @grafvonb
- Fixes #3427
Generated by 🛠️ Fix Bug from Labeled Issue for issue #3427 · 449.5 AIC · ⌖ 15.2 AIC · ⊞ 34K · ◷