contentful / contentful-migration

🚚 Migration tooling for contentful
MIT License
324 stars 149 forks source link

Ignore unrelated errors in migrations #186

Open gkulasik-livongo opened 5 years ago

gkulasik-livongo commented 5 years ago

Expected Behavior

There is some override or catching mechanism within a migration block that can ignore errors (such as notResolvable) that are not related to the data being migrated.

Actual Behavior

Situation: I am migrating some text content (simple text change with transformEntries) and the contentType has a reference field to an asset (image). For 2 out of 2000+ entries there is a bad reference which fails the migration. I cannot change the content to fix those references because those are controlled by a different team. I am only able to migrate/edit the text fields. My migration fails because of these bad references that I cannot change.

Possible Solution

Is there, or can there be, a way (within the JS CLI migration tool) to 'ignore' exceptions and save content (override) or to catch exceptions and ignore so that the entire migration is not marked as a failure.

This can be a flag on the migration CLI call:

contentful space migration -s XXX -e XXX test_migration.js --mt XXX --ignore-errors

or an additional option to transformEntries:

migration.transformEntries({
            contentType: "ContentType",
            from: ['Field1'],
            to: ['Field2'],
            ignoreValidationErrors: true,
            ...

Steps to Reproduce

  1. Setup a content type with a reference field (image asset for example)
  2. Create a single valid content entry of that content type
  3. Delete the referenced image (don't remove the reference on the content entry)
  4. Try to migrate the content using transformEntries (or any other migration)
  5. Migration will be marked as a failure with message similar to:
UnresolvedLinks: {
  "status": 422,
  "statusText": "Unprocessable Entity",
  "message": "Validation error",
  "details": {
    "errors": [
      {
        "name": "notResolvable",
        "link": {
          "type": "Link",
          "linkType": "Asset",
          "id": "XXXXX"
        },
        "path": [
          "fields",
          "images",
          "en-US",
          0
        ]
      }
    ]
  },
  "request": {
    "url": "https://api.contentful.com:443/spaces/XXXX/environments/XXX/entries/XXXXX/published",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-User-Agent": "app contentful.cli/0.26.5; feature space-migration; sdk contentful-management.js/5.2.1; platform node.js/v10.7.0; os macOS/18.5.0;",
      "Authorization": "Bearer ...81aee",
      "user-agent": "node.js/v10.7.0",
      "Accept-Encoding": "gzip",
      "X-Contentful-Version": 4,
      "X-Contentful-Content-Type": "imagePage"
    },
    "method": "put"
  },
  "requestId": "e47cf5f42d6be5407cd04809e5b28e71"
}
    at errorHandler (/usr/local/lib/node_modules/contentful-cli/node_modules/contentful-migration/node_modules/contentful-management/dist/contentful-management.node.js:13173:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Context

I think the context was covered a bit in previous sections but essentially I need to apply a universal change to a text field and publish the updated text. The migration fails because of an unresolved reference (asset) unrelated to the change I am making.

I generally support the validation and think it should be on by default but really need there to be an override to accomplish what we are looking to do given there are many people's hands in the content and we cannot have our CI fail because one entry has a bad reference, it is ok if it gets skipped and we log the issue but other migrations need to run afterward which get blocked by this failure/validation.

Environment

freder commented 5 years ago

I'm also currently running into notResolvable errors.

yvesgurcan commented 1 year ago

I am running into the same issue when modifying a content type that has a link to an entry with an image into that linked entry to get the image itself. When running into broken references to images, the migration fails and the content model ends up being half-modified since the first steps of the migration are indeed executed but not the ones after the step with the entities that do not resolve, which is most likely the least desirable state.

acn-husnie-edres commented 10 months ago

I also encountered the same issue, need to manually fix the content that is not related to migration. LOL

what is the status of this issue?

image

sergiusticiffw commented 6 months ago

I have the same issue. any updates here?

ickeundso commented 1 month ago

Hi Contentful Team no answer yet , this issue is 5 years open. Every time im facing an issue like that I have to impolite some exclude list handling to deal with that. Not only an ignore error switch would be nice to have , also an error report which entry has been skipped.