fix: Error in afterSave trigger for Parse.Role due to name field (#9883)

This commit is contained in:
Antoine Cormouls
2025-10-22 14:12:51 +02:00
committed by GitHub
parent 1de329d900
commit eb052d8e6a
3 changed files with 87 additions and 5 deletions

View File

@@ -1743,6 +1743,14 @@ RestWrite.prototype.buildParseObjects = function () {
const readOnlyAttributes = className.constructor.readOnlyAttributes
? className.constructor.readOnlyAttributes()
: [];
// For _Role class, 'name' cannot be set after the role has an objectId.
// In afterSave context, _handleSaveResponse has already set the objectId,
// so we treat 'name' as read-only to avoid Parse SDK validation errors.
const isRoleAfterSave = this.className === '_Role' && this.response && !this.query;
if (isRoleAfterSave && this.data.name && !readOnlyAttributes.includes('name')) {
readOnlyAttributes.push('name');
}
if (!this.originalData) {
for (const attribute of readOnlyAttributes) {
extraData[attribute] = this.data[attribute];