Motivation:
2 developers export a newly created entities in two separate branches. These entites are different and test different things. The NID / VID / TID of both exported items conflict. After merging to a central branch, the import is broken and needs to be fixed.

Possible solution:
On import of the default content, regenerate the IDs. On export of default content, regenerate IDs. This will eliminate most conflicts. Entity references will have to be dealt with in that their new IDs are also mapped.

Comments

jjchinquist created an issue. See original summary.

andypost’s picture

Status: Active » Closed (duplicate)
Related issues: +#2698425: Do not re-import existing entities
jjchinquist’s picture

Status: Closed (duplicate) » Active

This isn't a duplicate. Our desired workflow is that we have a set of default content that represents much of the abilities of the website. We import it for testing instances of the website, not on production. So we import all content into an empty database. It has to do with when default content is updated in two separate branches of the project and then conflicts are created due to the ID numbers being in conflict.

Phil Wolstenholme’s picture

I'm running into this issue very frequently too.

RumyanaRuseva’s picture

This is not a duplicate of #2698425: Do not re-import existing entities but it's related.
I believe there should be an option in the export command flagging whether the entity id should be exported. The module is designed to work with uuid as main identifier, and we usually do not need to export the entity id.

As a workaround you can currently manually edit the exported json file and remove the entity id to avoid conflicts.
Importer works perfectly with empty entity id.

geerlingguy’s picture

Version: 8.x-1.0-alpha7 » 8.x-1.x-dev

Same issue here, and the workaround posted by @RumyanaRuseva worked well.

michael_wojcik’s picture

Status: Active » Needs review
StatusFileSize
new8.7 KB

Taking inspiration from @RumyanaRuseva in #5, I made a patch that adds a new drush option `--skip-entity-ids` to the existing drush commands, which will allow users to automatically remove all references to specific entity IDs during the content export process. The resulting JSON files can then be imported into any existing Drupal environment without worrying about conflicting IDs in the database. This work resulted from a real-world use case where we needed to leverage the default_content module to import content into an already existing site in Production.

Status: Needs review » Needs work

The last submitted patch, 7: default_content-skip-entity-ids-2969631-7.patch, failed testing. View results

Phil Wolstenholme’s picture

#7 gave me a The "--skip-entity-ids" option does not exist, perhaps because I am using Drush 9?

I'll take a look at src/Commands/DefaultContentCommands.php and see if I can update the patch this afternoon.

Phil Wolstenholme’s picture

Here's an updated patch that adds (hopefully!) Drush 9+ support. I don't use Drush 8 so haven't been able to check whether Drush 8 has been affected by my changes. This patch hasn't been tested in production or any other environment as I stopped working on it after discovering that Entity Reference Revisions fields (e.g. the ones used for Paragraphs) require an ID, so this patch and similar ones will break references to Paragraphs on your site.

I've attached some related issues, this idea could work if ERR updates to allow serialised ERR fields to use a UUID rather than target ID.

berdir’s picture

I've created a new 2.0.x branch that uses a custom normalization and the ids and a lot of other things that are not useful are not exported anymore.

1.x is in maintenance mode and and won't receive future features anymore.

Phil Wolstenholme’s picture

@Berdir that sounds excellent! Does it get around the Entity Reference Revisions issue by putting the nested entities in a single file rather than linking Paragraphs across multiple files by ID?

berdir’s picture

Status: Needs work » Closed (won't fix)

Yes, 2.0.x supports ERR composite entities like paragraphs out of the box and puts them in a single file. We already did that in the past with a patch for default_content and one for ERR, but now it just works. See the project page for more features of the 2.0.x branch.

I'm closing isuses that are resolved in 2.0.x as won't fix as the 1.x branch isn't actively maintained anymore and new features won't be implemented.

meanderix’s picture

@Berdir How does 2.0.x handle non-numeric entity ids? AFAICT this results in error Field 'id' doesn't have a default value upon import.

berdir’s picture

that's quite possible, but that's a different issue than this. Patches to check for ID being an integer/serial are welcome.