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
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
Comment #3
drale01 commentedConfirming 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.
Comment #6
tbkot commentedThe "product_id" is now removed in the exported YML as well as the dependency on the product.
Comment #9
jsacksick commentedMerged!! Thank you!