Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deriveLinkedEntries migration fails #1836

Open
akarpov91 opened this issue Feb 14, 2023 · 0 comments
Open

deriveLinkedEntries migration fails #1836

akarpov91 opened this issue Feb 14, 2023 · 0 comments

Comments

@akarpov91
Copy link

akarpov91 commented Feb 14, 2023

Expected Behavior

Using the Contenful Migration CLI 'deriveLinkedEntries' script to add an existing content model 'seo' as a reference within another existing content model 'pageBlogPost'.

Actual Behavior

Migration fails for some entries with 400 and 422 errors.

Steps to Reproduce

  1. Create a new seo field in the blog post content type as a reference content type SEO.
module.exports = function (migration) {
  // Create a new seo field in the blog post content type.
  const blogPost = migration.editContentType('pageBlogPost')
  blogPost
    .createField('seo_ref')
    .name('Compose: SEO')
    .type('Link')
    .linkType('Entry')
    .validations([
      {
        linkContentType: ['seo'],
      },
    ])
}
  1. Edit each blog entries new seo_ref field using existing fields in blogs such as 'metaTitle', 'metaDescription', etc.
module.exports = function (migration) {
  migration.deriveLinkedEntries({
    // Start from blog post's meta field
    contentType: 'pageBlogPost',
    from: ['metaTitle', 'metaDescription', 'slug'],
    // This is the field we created in 01-add-seo-ref.js, which will hold the link to the derived category entries.
    toReferenceField: 'seo_ref',
    // The new entries to create are of type 'category'.
    derivedContentType: 'seo',
    derivedFields: ['title', 'description'],
    identityKey: async (from) => {
      // The category name will be used as an identity key.
      return from.slug['en-US']
    },
    deriveEntryForLocale: async (from, locale) => {
      if (locale !== 'en-US') {
        return
      }
      return {
        title: from['metaTitle'][locale],
        description: from['metaDescription'][locale],
      }
    },
  })
}

Context

We have two existing content models 'pageBlogPost' and 'seo'. I'm trying to add 'seo' as a reference field into the 'pageBlogPost' and modify each blog entries 'seo' fields such as 'title' and 'description' with existing blog fields such as 'metaTitle' and 'metaDescription'.

This script succeeds for the majority of entries but fails overall due to a few of them erring. See errors below.
Errors

{
  "details": {},
  "message": "Invalid resource id",
  "request": {
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Accept-Encoding": "gzip",
      "Authorization": "Bearer ...9-m5k",
      "CF-Sequence": "2b19b16b-f274-4f68-8ea6-544e74f0a25c",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-Content-Type": "seo",
      "X-Contentful-User-Agent": "app contentful.cli/0.0.0-determined-by-semantic-release; feature space-migration; sdk contentful-management-plain.js/7.54.2; platform node.js/v19.0.0; os macOS/v19.0.0;",
      "X-Contentful-Version": 1,
      "user-agent": "node.js/v19.0.0"
    },
    "method": "put",
    "url": "spaces/xxxxxx/environments/seo/entries/introducing-snapshot-analyzer-interactive-investigations-for-deep-systems/published"
  },
  "requestId": "5c7cab13-d2c2-4542-b299-673473e7e784",
  "status": 400,
  "statusText": "Bad Request"
}
{
  "details": {
    "errors": [
      {
        "link": {
          "id": "introducing-snapshot-analyzer-interactive-investigations-for-deep-systems",
          "linkType": "Entry",
          "type": "Link"
        },
        "name": "notResolvable",
        "path": [
          "fields",
          "seo_ref",
          "en-US"
        ]
      }
    ]
  },
  "message": "Validation error",
  "request": {
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Accept-Encoding": "gzip",
      "Authorization": "Bearer ...9-m5k",
      "CF-Sequence": "2b19b16b-f274-4f68-8ea6-544e74f0a25c",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-Content-Type": "pageBlogPost",
      "X-Contentful-User-Agent": "app contentful.cli/0.0.0-determined-by-semantic-release; feature space-migration; sdk contentful-management-plain.js/7.54.2; platform node.js/v19.0.0; os macOS/v19.0.0;",
      "X-Contentful-Version": 5,
      "user-agent": "node.js/v19.0.0"
    },
    "method": "put",
    "url": "spaces/xxxxxx/environments/seo/entries/6a7NPz0lq6QiHdSNf8gOIW/published"
  },
  "requestId": "eee005e0-4375-4cb9-9800-ccc2912020c8",
  "status": 422,
  "statusText": "Unprocessable Entity"
}

Environment

  • Language Version: v19.0.0
  • Package Manager Version: 8.19.2
  • Browser Version:
  • Operating System: Darwin MREM5C7EE61C 21.6.0 Darwin Kernel Version 21.6.0: Mon Dec 19 20:43:09 PST 2022; root:xnu-8020.240.18~2/RELEASE_ARM64_T6000 arm64
  • Package Version: [email protected] and [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant