Parse-SDK-JS icon indicating copy to clipboard operation
Parse-SDK-JS copied to clipboard

_Role afterSave validation error

Open michalmichalewski opened this issue 6 months ago • 1 comments

New Issue Checklist


Issue Description

Adding an afterSave hook on the built-in _Role class causes a validation error, even if the hook is completely empty and makes no changes to the object.

The error is:

A role's name can only be set before it has been saved.

This seems to be triggered due to internal behavior when handling _Role objects during the afterSave lifecycle. This bug prevents any post-save logic from being used with _Role.


Steps to reproduce

  1. Add this Cloud Code to Parse:
Parse.Cloud.afterSave('_Role', async (request) => {
  // no-op
});
  1. Run the following in your client or console:
const role = new Parse.Role('Admin', new Parse.ACL());
await role.save(); // fails
  1. Observe the validation error, even though no modification is made in the hook.

Actual Outcome

save() fails with the following error:

A role's name can only be set before it has been saved.

Expected Outcome

Saving a _Role with an empty afterSave hook should succeed, as long as the name field isn't modified.


Environment

Server

  • Parse Server version: 8.1.0
  • Operating system: Ubuntu 22.04
  • Local or remote host: Remote (self-hosted, Docker)

Database

  • System: MongoDB
  • Database version: 6.0.x
  • Host: MongoDB Atlas

Client

  • "parse": "^6.1.1"

Logs

Set VERBOSE=1 but the only error printed is:

A role's name can only be set before it has been saved.

michalmichalewski avatar May 27 '25 08:05 michalmichalewski

🚀 Thanks for opening this issue!

ℹ️ You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.