Repository navigation
BUG: Product cloning retains source inventory links in CodebaseResource #601
Description
Describe the bug
When cloning a product with both "Components, Packages, and Dependencies" (copy_inventory) and "Codebase resources" (copy_codebase_resources) checked, the cloned CodebaseResource still references the original product's ProductPackage and ProductComponent instead of the newly cloned ones.
In ProductCloneForm.save(), relations are duplicated using clone_related_objects(), which sets resource.product = target_product but leaves product_package_id and product_component_id pointing to the source product's records.
Because clone_related_objects() calls .save() directly, model validation is bypassed during the clone. But if someone later opens that cloned resource in Admin and clicks Save, Django blocks it with a validation error because CodebaseResource.clean() explicitly forbids linking packages/components from another product. Also, if the original product is ever deleted, these relations get set to NULL due to SET_NULL.
To Reproduce
- Create a product (e.g.
Product A 1.0.0). - Add a package to it (e.g.
pkg:npm/left-pad@1.3.0). - Add a codebase resource (
/src/index.js) toProduct Aand link itsProduct packagefield to that package. - Clone
Product Awith bothcopy_inventoryandcopy_codebase_resourcesenabled to createProduct A 2.0.0 (copy). - Open the cloned codebase resource in Django Admin (
/admin/product_portfolio/codebaseresource/<id>/change/). - Click Save without changing anything.
- See validation error:
pkg:npm/left-pad@1.3.0 is not available on Product A 2.0.0 (copy).
Expected behavior
- When both inventory and codebase resources are cloned,
CodebaseResource.product_packageandproduct_componentshould be remapped to the newly created cloned records on the target product. - If codebase resources are cloned without inventory (
copy_inventoryunchecked), the cross-product package/component foreign keys should be cleared to keep the data clean.
Screenshots
- Source product (
Product A 1.0.0) with/src/index.jsmapped toleft-pad:
- Cloned product (
Product A 2.0.0 (copy)) created with both inventory and codebase resources:
- Saving the cloned resource in Django Admin triggers
clean()validation error:
Context (OS, Browser, Device, etc.):
- DejaCode: 6.0.0 (commit 8fc6013)
- OS: Windows
- Browser: Chrome
- Environment: Local Docker instance
Activity
fix: relink codebase resources on product save as new #601
fix: relink cloned codebase resources to the cloned inventory #601 (#602
tdruez commentedon Oct 21, 2026
@darshankerkar Thanks for reporting this one! Fixed in #602