Skip to content

Auto-remove addons from bundle if they were removed - #1102

Open
martastain wants to merge 8 commits into
developfrom
remove-non-existent-addons-from-bundle-upon-updating
Open

martastain wants to merge 8 commits into
developfrom
remove-non-existent-addons-from-bundle-upon-updating

Conversation

@martastain

Copy link
Copy Markdown
Member

This pull request adds validation to the handling of addons in the update_bundle function. Now, before updating a bundle, the code checks that each addon listed actually exists in the AddonLibrary. If an addon does not exist, it is removed from the bundle and a warning is logged. This helps prevent invalid or non-existent addons from being saved in the bundle.

(And most importantly - it gives back the ability to archive/change bundles, when they contain an addon that was removed, because originally, this triggered an error during bundle validation)

@martastain martastain self-assigned this Aug 31, 2026
@martastain martastain added the type: bug Something isn't working label Aug 31, 2026
@martastain
martastain requested review from BigRoy and m-u-r-p-h-y and a lite review from Copilot August 31, 2026 11:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new cleanup block currently catches overly broad exceptions and can mis-handle malformed/None addon data, potentially masking real failures or raising at runtime.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves robustness of update_bundle by cleaning up bundle addon entries that no longer exist in AddonLibrary, so bundles can still be archived/updated even after an addon/version has been removed from the server.

Changes:

  • Validate existing bundle data["addons"] against AddonLibrary during update_bundle.
  • Automatically remove missing addons/versions from the bundle and log a warning.
File summaries
File Description
api/bundles/bundles.py Adds pre-validation/cleanup of persisted bundle addons before running bundle validation and applying patches.
Review details

Suppressed comments (1)

api/bundles/bundles.py:268

  • Catching Exception here will also swallow unexpected failures inside addon loading/initialization and silently mutate the bundle, which can hide real problems. Since AddonLibrary.addon() documents raising NotFoundException for missing addons/versions, catch that specific exception (and handle None versions explicitly) to avoid masking unrelated errors.
        for addon_name, addon_version in list(addons.items()):
            try:
                _ = AddonLibrary.addon(addon_name, addon_version)
            except Exception:
                logger.warning(
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread api/bundles/bundles.py Outdated

@BigRoy BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code makes sense - @kalisp can you review it?

@BigRoy
BigRoy requested a review from kalisp September 2, 2026 10:43
@kalisp

kalisp commented Sep 2, 2026

Copy link
Copy Markdown
Member

How is this supposed to be working?

Removed addon (server) (without restart), I can still select him in the Bundle addon version dropdown (which is I guess expected). But when I select it, it seems it gets saved ok.

I created new copy of bundle, selected that missing addon and saved it fine. (But updated method is probably not called, but create_new_bundle is called instead.)

(After server restart addon version gets removed in the bundle. If that is new expected behavior, then it work :).)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new addon pre-validation can incorrectly remove valid project-bundle placeholder versions (e.g. __inherit__ / __disable__) because they are not real addon versions and will always fail AddonLibrary.addon() lookups.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread api/bundles/bundles.py Outdated
martastain and others added 3 commits September 7, 2026 11:14
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved validation and cache-handling issues remain for patched references and addon placeholders.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (2)

api/bundles/bundles.py:393

  • This validation covers only the stored data["addons"]; the patch loop below checks only that the addon name exists and then accepts any semver-shaped but unavailable version. With force=True, check_bundle is skipped and that invalid patched version is persisted, so the new cleanup does not cover all addons being saved. Validate the merged addon map (or call addon_library.addon here, while honoring the placeholder values) before writing it.
                addon_definition = addon_library.get(addon_name)
                if addon_definition is None:
                    logger.warning(f"Addon {addon_name} does not exist, ignoring")
                    continue

api/bundles/bundles.py:314

  • The new installer/dependency checks sanitize only values read from data, but later patch.installer_version and patch.dependency_packages are assigned directly. A PATCH can therefore reintroduce a deleted installer or dependency reference (and check_bundle does not validate these files), leaving invalid references persisted; validate the post-patch values before constructing the saved data.
            existing_dependency_packages = await list_dependency_packages()
            for platform, filename in list(dependency_packages.items()):
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread api/bundles/bundles.py
Comment on lines +280 to +282
# Project bundle placeholders (and disabled addons) are not real versions.
# Only validate addon existence in that case.
if addon_version in (None, "__inherit__", "__disable__"):
Comment thread api/bundles/bundles.py

if patch.is_production is not None or patch.is_staging is not None or patch.addons:
await AddonLibrary.clear_addon_list_cache()
await addon_library.clear_addon_list_cache()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants