Skip to content

Conversation

psychedelicious
Copy link
Collaborator

Summary

When installing a model, the previous, graceful logic would increment a suffix on the destination path until found a free path for the model.

But because model file installation and record creation are not in a transaction, we could end up moving the file successfully and fail to create the record:

  • User attempts to install an already-installed model
  • Attempt to move the downloaded model from download tempdir to destination path
  • The path already exists
  • Add _1 or similar to the path until we find a path that is free
  • Move the model
  • Create the model record
  • FK constraint violation bc we already have a model w/ that name, but the model file has already been moved into the invokeai dir.

Related Issues / Discussions

Closes #8416

QA Instructions

  • Install a model
  • Try to install the same model again
  • It should fail early without creating a duplicate model file

Merge Plan

n/a

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added python PRs that change python files services PRs that change app services labels Aug 12, 2025
@psychedelicious psychedelicious enabled auto-merge (rebase) August 13, 2025 00:35
… path

When installing a model, the previous, graceful logic would increment a
suffix on the destination path until found a free path for the model.

But because model file installation and record creation are not in a
transaction, we could end up moving the file successfully and fail to
create the record:
- User attempts to install an already-installed model
- Attempt to move the downloaded model from download tempdir to
destination path
- The path already exists
- Add `_1` or similar to the path until we find a path that is free
- Move the model
- Create the model record
- FK constraint violation bc we already have a model w/ that name, but
the model file has already been moved into the invokeai dir.

Closes #8416
@psychedelicious psychedelicious force-pushed the psyche/fix/duplicate-model-during-install branch from 8d611da to b56ca88 Compare August 13, 2025 00:35
@psychedelicious psychedelicious merged commit c506955 into main Aug 13, 2025
12 checks passed
@psychedelicious psychedelicious deleted the psyche/fix/duplicate-model-during-install branch August 13, 2025 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python PRs that change python files services PRs that change app services
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]:
2 participants