{"record":{"id":"de513b645a5c0811","repo":"gitroomhq/postiz-app","slug":"failed-to-update-the-post","errorCode":null,"errorMessage":"Failed to update the post","messagePattern":"Failed to update the post","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts","lineNumber":1110,"sourceCode":"          label: t.tag.name,\n        })),\n        posts: [\n          {\n            integration,\n            group: root.group,\n            settings: mergedSettings,\n            value,\n          },\n        ],\n      } as any,\n      creationMethod,\n      // Keep the group stable: a client may have the calendar open while the\n      // settings are updated out of band, and the calendar links posts by group.\n      true\n    );\n\n    if (!output) {\n      throw new BadRequestException('Failed to update the post');\n    }\n\n    return {\n      postId: output.postId,\n      publishDate: date,\n    };\n  }\n\n  async separatePosts(content: string, len: number) {\n    return this._openaiService.separatePosts(content, len);\n  }\n\n  async changeState(id: string, state: State, err?: any, body?: any) {\n    return this._postRepository.changeState(id, state, err, body);\n  }\n\n  async changePostStatus(\n    orgId: string,","sourceCodeStart":1092,"sourceCodeEnd":1128,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts#L1092-L1128","documentation":"After validation, the update is persisted via updatePost on the repository (with the group kept stable for calendar grouping). If the repository returns a falsy result — typically the underlying update affected no rows — the service surfaces 'Failed to update the post'.","triggerScenarios":"Updating a post id that was deleted between the initial fetch and the repository write, or a repository-level failure/rollback that returns null instead of throwing.","commonSituations":"Concurrent deletion by another team member mid-edit; race with the scheduler changing the post; Prisma update matching zero records; transient DB issues.","solutions":["Refetch the post by id; if it's gone, refresh the calendar and create a new post","Retry the update once after re-fetching fresh post data","Check backend logs for a concurrent delete or scheduler mutation on the same post id","Avoid holding editor sessions open across long periods on soon-to-change posts"],"exampleFix":"// before\nawait updatePost(orgId, postId, body); // once, assume success\n// after\nlet result = await updatePost(orgId, postId, body).catch(() => null);\nif (!result) {\n  const fresh = await getPostById(orgId, postId);\n  if (fresh) result = await updatePost(orgId, postId, body);\n}","handlingStrategy":"retry","validationCode":"const post = await getPostById(orgId, postId);\nif (!post) { await refreshCalendar(); return; }","typeGuard":null,"tryCatchPattern":"try {\n  await updatePost(orgId, postId, body);\n} catch (e) {\n  if (/Failed to update the post/.test(String(e?.response?.message ?? e))) {\n    const fresh = await getPostById(orgId, postId);\n    if (fresh) await updatePost(orgId, postId, body); // one retry after refetch\n    else await refreshCalendar();\n  } else throw e;\n}","preventionTips":["Refetch before retrying updates","Detect concurrent deletes via the posts list and reconcile UI state","Keep editor sessions short for soon-to-change posts"],"tags":["posts","update","concurrency","database"],"backgroundTag":"write-conflict-retry","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}