Skip to content

Fix replace_key() regression that broke checkpoint dict ordering - #17488

Closed
pminko101 wants to merge 1 commit into
AUTOMATIC1111:devfrom
pminko101:pminko101-aria-gpt
Closed

pminko101 wants to merge 1 commit into
AUTOMATIC1111:devfrom
pminko101:pminko101-aria-gpt

Conversation

@pminko101

Copy link
Copy Markdown

Why

A prior "optimization" to replace_key() in modules/sd_models.py replaced the O(n) key-reordering logic with a simple delete-then-reinsert. That change relied on Python's dict insertion order, but a re-inserted key is appended at the end of the dict rather than staying at its original position. This silently broke checkpoint list ordering whenever a model's title changes after calculate_shorthash() is called (e.g. checkpoint dropdown/API ordering shifting unexpectedly).

What changed

Restored order-preserving key replacement in replace_key():

  • Renames a key in place, keeping its original position in the dict.
  • Falls back to appending when the key to replace doesn't exist.
  • Additionally handles the case where new_key already exists elsewhere in the dict (removes the stale entry first) so no duplicate/orphaned entries can occur.

Notes for reviewers

  • Verified behavior with a standalone script covering: in-place rename preserving order, missing-key append, and rename colliding with an existing key.
  • No behavior change for callers (CheckpointInfo.calculate_shorthash() is the only call site) beyond fixing the ordering regression.

A prior optimization to replace_key() deleted and re-added the key,
which appended it at the end of the dict instead of preserving its
original position. This broke checkpoint ordering when a model's
title changes after calculate_shorthash(). Restore order-preserving
behavior while also handling collisions with an existing new_key.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pminko101
pminko101 changed the base branch from master to dev September 10, 2026 16:09
@w-e-w

w-e-w commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

please stop

@w-e-w w-e-w closed this Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants