500 Internal Server Error when updating relation field

System Information
  • Strapi Version: 4.5.3
  • Operating System: Mac OS 12.6
  • Database: mysql
  • Node Version: 16
  • NPM Version: 6
  • Yarn Version: 1.22.19

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.

If there are any further details you need to know, do not hesitate to ask.

Any help would be greatly appreciated.

Whats the output in the strapi console (aka the terminal)? When you do this as a 500 error will log the error. This should at least point in the right direction.

This is the error I can see in the server logs

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 have tried updating to @strapi/strapi version 4.10.7 and the error no longer persists