英文:
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
{
"data": null,
"error": {
"status": 500,
"name": "InternalServerError",
"message": "Internal Server Error"
}
}
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
{
"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"]
}
}
}
and this is the category schema
{
"kind": "collectionType",
"collectionName": "categories",
"info": {
"singularName": "category",
"pluralName": "categories",
"displayName": "Category",
"description": ""
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"Name": {
"type": "string"
}
}
}
in the PUT
request this is the categories
property and it's value in the body of the request
{
"disconnect": [],
"connect": [
{
"id": 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
{
"SEO": {
"PageTitle": ""
},
"categories": {
"disconnect": [],
"connect": [
{
"id": 3
}
]
},
"Slug": "article-1",
"Content": ""
}
Then when attempting to immediately update the article by adding a new category, this is the PUT
body
{
"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": "",
"MetaDescription": null
},
"categories": {
"disconnect": [],
"connect": [
{
"id": 2
}
]
},
"Poster": null,
"Gallery": null,
"createdBy": 1,
"updatedBy": 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.<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)
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论