Describe your bug or feature request.

When exporting a commerce_product and its associated commerce_product_variation entities using the Default Content API in Drupal Core, the resulting YAML files contain a circular dependency that makes import impossible:
- commerce_product has a variations field referencing its variation entities
- commerce_product_variation has a product_id back-reference to its parent product

The exported YAML for each entity contains a depends key listing the UUIDs of referenced entities. Because both entities reference each other, neither can be imported first - Drupal's importer cannot resolve the dependency graph and the import fails.

This is not specific to Commerce. Any entity type pair that holds bidirectional references (owner → child, child → parent back-reference) will produce the same unresolvable cycle.

Workaround

Manually edit the exported YAML for the "child" entity to remove the back-reference field and its depends entry:

  # commerce_product_variation/<uuid>.yml — remove:
  product_id:
    - target_uuid: <product-uuid>

  # and remove the product UUID from the depends block:
  depends:
    - <product-uuid>   # ← remove this line

Issue fork commerce-3580176

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

zaporylie created an issue. See original summary.

pallabi_mondal made their first commit to this issue’s fork.

drale01’s picture

Confirming this from a Drupal CMS `drush site:export` / site-template workflow with Commerce products + variations (including translations).

The product ↔ variation circular dependency makes Default Content import fail: `commerce_product.variations` and `commerce_product_variation.product_id` both create `depends` edges.

What worked for us as an export-side workaround:

1. On `commerce_product_variation`, do not export `product_id` (so variations can import first; the product’s `variations` field re-links them on save).
2. On `commerce_product`, skip exporting `variations` for non-default translations (the field is not translatable; re-resolving it on translation export/import can clear or break references).

We currently keep this in `drupal_cms_helper` until Commerce ships a proper `PreExportEvent` subscriber. I see there is already an issue fork here — happy to test it and report back, or help align it with the above if anything is still missing.

tbkot made their first commit to this issue’s fork.

tbkot’s picture

Status: Active » Needs review

The "product_id" is now removed in the exported YML as well as the dependency on the product.

jsacksick made their first commit to this issue’s fork.

  • jsacksick committed 6a551678 on 3.x authored by tbkot
    fix: #3580176 Commerce product/variation circular dependency makes...
jsacksick’s picture

Status: Needs review » Fixed

Merged!! Thank you!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.