Skip to content

BUG: Product cloning retains source inventory links in CodebaseResource #601

Closed

Description

@darshankerkar

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

  1. Create a product (e.g. Product A 1.0.0).
  2. Add a package to it (e.g. pkg:npm/left-pad@1.3.0).
  3. Add a codebase resource (/src/index.js) to Product A and link its Product package field to that package.
  4. Clone Product A with both copy_inventory and copy_codebase_resources enabled to create Product A 2.0.0 (copy).
  5. Open the cloned codebase resource in Django Admin (/admin/product_portfolio/codebaseresource/<id>/change/).
  6. Click Save without changing anything.
  7. 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_package and product_component should be remapped to the newly created cloned records on the target product.
  • If codebase resources are cloned without inventory (copy_inventory unchecked), the cross-product package/component foreign keys should be cleared to keep the data clean.

Screenshots

  1. Source product (Product A 1.0.0) with /src/index.js mapped to left-pad:
Image
  1. Cloned product (Product A 2.0.0 (copy)) created with both inventory and codebase resources:
Image
  1. Saving the cloned resource in Django Admin triggers clean() validation error:
Image

Context (OS, Browser, Device, etc.):

  • DejaCode: 6.0.0 (commit 8fc6013)
  • OS: Windows
  • Browser: Chrome
  • Environment: Local Docker instance

Activity

  1. added
    bugSomething isn't working
    enhancementNew feature or request
    design neededDesign details needed to complete the issue
    on Oct 20, 2026
  2. tdruez commented on Oct 21, 2026

    @tdruez
    Contributor

    @darshankerkar Thanks for reporting this one! Fixed in #602

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdesign neededDesign details needed to complete the issueenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions