Strapi内容管理器在更新关联字段时出现500内部服务器错误。

huangapple go评论52阅读模式
英文:

Strapi Content Manager 500 Internal Server Error when updating relation field

问题

我遇到一个问题,似乎只在现场生产网站上发生(在暂存网站或本地上不会发生),当尝试更新关系字段时,我在PUT请求期间收到以下错误消息:

{
    "data": null,
    "error": {
        "status": 500,
        "name": "InternalServerError",
        "message": "Internal Server Error"
    }
}

这个问题最近才出现,我实际上不确定应该在哪里查找解决此问题?

这是内容类型“article”的架构,其中包含出现问题的相关字段“category”:

{
  "kind": "collectionType",
  "collectionName": "articles",
  "info": {
    "singularName": "article",
    "pluralName": "articles",
    "displayName": "Articles",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "Title": {
      "type": "string",
      "required": true,
      "minLength": 1
    },
    "Slug": {
      "type": "uid",
      "targetField": "Title",
      "required": true
    },
    "SEO": {
      "type": "component",
      "repeatable": false,
      "component": "seo.seo",
      "required": true
    },
    "Excerpt": {
      "type": "text",
      "maxLength": 240
    },
    "categories": {
      "type": "relation",
      "relation": "oneToMany",
      "target": "api::category.category"
    },
    "Content": {
      "type": "richtext",
      "required": true
    },
    "Poster": {
      "type": "media",
      "multiple": false,
      "required": false,
      "allowedTypes": ["images", "files", "videos", "audios"]
    },
    "Gallery": {
      "type": "media",
      "multiple": true,
      "required": false,
      "allowedTypes": ["images", "files", "videos", "audios"]
    }
  }
}

这是类别模式:

{
  "kind": "collectionType",
  "collectionName": "categories",
  "info": {
    "singularName": "category",
    "pluralName": "categories",
    "displayName": "Category",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "Name": {
      "type": "string"
    }
  }
}

在PUT请求中,这是请求正文中的“categories”属性及其值:

{
    "disconnect": [],
    "connect": [
        {
            "id": 1
        }
    ]
}

内容类型“article”的初始创建是正常的,您可以选择类别,只有当您尝试更新“categories”时才会出现错误。

这是用于创建文章的POST正文:

{
    "SEO": {
        "PageTitle": ""
    },
    "categories": {
        "disconnect": [],
        "connect": [
            {
                "id": 3
            }
        ]
    },
    "Slug": "article-1",
    "Content": ""
}

然后,当尝试立即通过添加新类别来更新文章时,这是PUT正文:

{
    "id": 40,
    "Title": null,
    "Content": "",
    "createdAt": "2023-07-03T09:47:41.052Z",
    "updatedAt": "2023-07-03T09:47:41.052Z",
    "publishedAt": null,
    "Slug": "article-1",
    "Excerpt": null,
    "SEO": {
        "id": 30,
        "PageTitle": ""
    },
    "categories": {
        "disconnect": [],
        "connect": [
            {
                "id": 2
            }
        ]
    },
    "Poster": null,
    "Gallery": null,
    "createdBy": 1,
    "updatedBy": 1
}

这导致500错误。

我已经检查了管理面板的角色和用户权限插件角色,分别在没有问题的开发站点和生产站点上,它们似乎是匹配的。

在服务器日志中,我可以看到以下错误消息:

Error: ER_GTID_UNSAFE_CREATE_DROP_TEMPORARY_TABLE_IN_TRANSACTION: Statement violates GTID consistency: CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE can only be executed outside transactional context. These statements are also not allowed in a function or trigger because functions and triggers are also considered to be multi-statement transactions.
    at Query.Sequence._packetToError (/opt/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/opt/app/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/opt/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/opt/app/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/opt/app/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)

任何帮助将不胜感激。

英文:

I am having an issue that is only seemingly occurring on the live production website (it does not occur on a staging website or locally) when attempting to update a relation field, I get the following error during the PUT request

{
    &quot;data&quot;: null,
    &quot;error&quot;: {
        &quot;status&quot;: 500,
        &quot;name&quot;: &quot;InternalServerError&quot;,
        &quot;message&quot;: &quot;Internal Server Error&quot;
    }
}

This issue has just occurred recently and I'm not actually sure where to look to resolve this issue?

This is the schema of the content type article which holds the related field with the issue category

{
  &quot;kind&quot;: &quot;collectionType&quot;,
  &quot;collectionName&quot;: &quot;articles&quot;,
  &quot;info&quot;: {
    &quot;singularName&quot;: &quot;article&quot;,
    &quot;pluralName&quot;: &quot;articles&quot;,
    &quot;displayName&quot;: &quot;Articles&quot;,
    &quot;description&quot;: &quot;&quot;
  },
  &quot;options&quot;: {
    &quot;draftAndPublish&quot;: true
  },
  &quot;pluginOptions&quot;: {},
  &quot;attributes&quot;: {
    &quot;Title&quot;: {
      &quot;type&quot;: &quot;string&quot;,
      &quot;required&quot;: true,
      &quot;minLength&quot;: 1
    },
    &quot;Slug&quot;: {
      &quot;type&quot;: &quot;uid&quot;,
      &quot;targetField&quot;: &quot;Title&quot;,
      &quot;required&quot;: true
    },
    &quot;SEO&quot;: {
      &quot;type&quot;: &quot;component&quot;,
      &quot;repeatable&quot;: false,
      &quot;component&quot;: &quot;seo.seo&quot;,
      &quot;required&quot;: true
    },
    &quot;Excerpt&quot;: {
      &quot;type&quot;: &quot;text&quot;,
      &quot;maxLength&quot;: 240
    },
    &quot;categories&quot;: {
      &quot;type&quot;: &quot;relation&quot;,
      &quot;relation&quot;: &quot;oneToMany&quot;,
      &quot;target&quot;: &quot;api::category.category&quot;
    },
    &quot;Content&quot;: {
      &quot;type&quot;: &quot;richtext&quot;,
      &quot;required&quot;: true
    },
    &quot;Poster&quot;: {
      &quot;type&quot;: &quot;media&quot;,
      &quot;multiple&quot;: false,
      &quot;required&quot;: false,
      &quot;allowedTypes&quot;: [&quot;images&quot;, &quot;files&quot;, &quot;videos&quot;, &quot;audios&quot;]
    },
    &quot;Gallery&quot;: {
      &quot;type&quot;: &quot;media&quot;,
      &quot;multiple&quot;: true,
      &quot;required&quot;: false,
      &quot;allowedTypes&quot;: [&quot;images&quot;, &quot;files&quot;, &quot;videos&quot;, &quot;audios&quot;]
    }
  }
}

and this is the category schema

{
  &quot;kind&quot;: &quot;collectionType&quot;,
  &quot;collectionName&quot;: &quot;categories&quot;,
  &quot;info&quot;: {
    &quot;singularName&quot;: &quot;category&quot;,
    &quot;pluralName&quot;: &quot;categories&quot;,
    &quot;displayName&quot;: &quot;Category&quot;,
    &quot;description&quot;: &quot;&quot;
  },
  &quot;options&quot;: {
    &quot;draftAndPublish&quot;: true
  },
  &quot;pluginOptions&quot;: {},
  &quot;attributes&quot;: {
    &quot;Name&quot;: {
      &quot;type&quot;: &quot;string&quot;
    }
  }
}

in the PUT request this is the categories property and it's value in the body of the request

{
    &quot;disconnect&quot;: [],
    &quot;connect&quot;: [
        {
            &quot;id&quot;: 1
        }
    ]
}

The initial creation of the content type article is fine, you can select the categories, it's only once you attempt to update the categories does the error arise.

This is the body on the POST for creating an article

{
    &quot;SEO&quot;: {
        &quot;PageTitle&quot;: &quot;&quot;
    },
    &quot;categories&quot;: {
        &quot;disconnect&quot;: [],
        &quot;connect&quot;: [
            {
                &quot;id&quot;: 3
            }
        ]
    },
    &quot;Slug&quot;: &quot;article-1&quot;,
    &quot;Content&quot;: &quot;&quot;
}

Then when attempting to immediately update the article by adding a new category, this is the PUT body

{
    &quot;id&quot;: 40,
    &quot;Title&quot;: null,
    &quot;Content&quot;: &quot;&quot;,
    &quot;createdAt&quot;: &quot;2023-07-03T09:47:41.052Z&quot;,
    &quot;updatedAt&quot;: &quot;2023-07-03T09:47:41.052Z&quot;,
    &quot;publishedAt&quot;: null,
    &quot;Slug&quot;: &quot;article-1&quot;,
    &quot;Excerpt&quot;: null,
    &quot;SEO&quot;: {
        &quot;id&quot;: 30,
        &quot;PageTitle&quot;: &quot;&quot;,
        &quot;MetaDescription&quot;: null
    },
    &quot;categories&quot;: {
        &quot;disconnect&quot;: [],
        &quot;connect&quot;: [
            {
                &quot;id&quot;: 2
            }
        ]
    },
    &quot;Poster&quot;: null,
    &quot;Gallery&quot;: null,
    &quot;createdBy&quot;: 1,
    &quot;updatedBy&quot;: 1
}

Which returns the 500 error.

I've checked the ADMINISTRATION PANEL Roles & USERS & PERMISSIONS PLUGIN Roles on both the dev site where there is no issue and the live site and they seem to match up.

on the server logs, I can see this error message

Error: ER_GTID_UNSAFE_CREATE_DROP_TEMPORARY_TABLE_IN_TRANSACTION: Statement violates GTID consistency: CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE can only be executed outside transactional context.  These statements are also not allowed in a function or trigger because functions and triggers are also considered to be multi-statement transactions.
    at Query.Sequence._packetToError (/opt/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/opt/app/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/opt/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/opt/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/opt/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.&lt;anonymous&gt; (/opt/app/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.&lt;anonymous&gt; (/opt/app/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)

Any help would be greatly appreciated.

答案1

得分: 0

我之前使用的是Strapi版本4.5.3,升级到了4.10.7后,问题不再存在。

英文:

I was previously on strapi version 4.5.3 and updated to 4.10.7 and the problem no longer persists.

huangapple
  • 本文由 发表于 2023年7月3日 18:01:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定