[#8] Duplicate-name conflict on paste/import — verify first #8
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Status: verify before coding
Do not implement until the current behavior is confirmed. Read
paste_json/dropEventinbcc.pyandapply_serversinbcc_core.py, then post a comment on this issue describing what actually happens today when a pasted/dropped server name collides with an existing one. If it silently overwrites, then code the fix. If it already prompts, close this issue.Problem (if behavior is silent overwrite)
parse_pasted_json_verbose/apply_serversmay silently overwrite an existing server when a pasted or drag-and-dropped server name matches one already present. Silent overwrite matches the "config got clobbered" complaint pattern.Proposed fix (if needed)
Add an explicit prompt (overwrite / rename / skip) when a pasted or dropped server name collides with an existing entry.
Acceptance criteria (if needed)
Relevant code
bcc_core.py::apply_servers(line 186)bcc_core.py::parse_pasted_json_verbose(line 531)bcc.pypaste/drop handlersInvestigated current behavior before touching anything, per the issue instructions.
Paste path (
PasteDialog→MainWindow.paste_json, bcc.py ~1623-1653, usingcore.parse_pasted_json_verbosein bcc_core.py ~700): on a name collision it already shows aQMessageBox.question— "'{name}' already exists. Replace it? Yes = replace · No = keep both (renamed)". Choosing "keep both" appends-2,-3, ... until a free name is found. This path was already safe.Drag-and-drop path (
MainWindow.dropEvent, bcc.py ~1826-1848): this did not go through the same prompt. It silently renamed any colliding server to a fixed"{name}-imported"suffix, with no check that the suffixed name was itself free:Two concrete problems:
"{name}-imported"was also already taken (e.g. dropping the same file twice, or a server that already ends in-imported), the code did nothing further — twoServerEntryobjects with the identical.nameend up inself.servers. That isn't visible immediately, butapply_servers()(bcc_core.py ~192-198) builds the on-diskmcpServersdict via{s.name: s.data for s in servers if s.enabled}— a plain dict comprehension, last-one-wins, no warning. So on Save, one of the two same-named entries is silently dropped, and its config is lost.So: paste already handled collisions safely; drag-and-drop did not, and had a latent silent-data-loss bug on repeated/edge-case collisions. This is a real gap, not just theoretical, so I'm implementing a fix rather than closing the issue.
Fix: extracted the collision-resolution used by paste (
-2,-3, ... loop) into a pure, tested functioncore.resolve_name_collision(name, existing) -> strin bcc_core.py, and factored bothpaste_jsonanddropEventto go through one sharedMainWindow._import_server(name, data)helper that always prompts (replace / keep-both-renamed) on collision and always renames via the guaranteed-unique resolver. Drag-and-drop now behaves identically to paste — no more silent overwrite/collapse. Added unit tests forresolve_name_collisionin tests/test_core.py (no-conflict passthrough, single collision, multiple taken suffixes, empty existing set, and a repeated-call scenario simulating a double-drop that previously could collide).PR incoming.