Unable to create User via custom API

Environment

Frappe Version: v15.98.1
Production: Frappe Cloud
Local (Development): Works as expected
Issue Scope: Occurs only in production environment

Description
I am creating a User using a custom whitelisted API with allow_guest=True.
The API works correctly in local development, but fails in production with a permission error related to Notification Settings.

Error Message

User Guest does not have doctype access via role permission
for document Notification Settings

@frappe.whitelist(allow_guest=True)def signup_user(email, password, name, phone):if frappe.db.exists("User", email):return {"success": False,"message": "Email or phone number already registered"}

roles = [
    {"role": "System Manager"},
]

user = frappe.get_doc({
    "doctype": "User",
    "email": email,
    "first_name": first_name,
    "last_name": last_name,
    "enabled": 0,
    "send_welcome_email": 0,
    "new_password": password,
    "roles": roles,
    "phone": phone
})

user.flags.ignore_permissions = True
user.flags.ignore_password_policy = True
user.insert()

return {
    "success": True,
    "message": "Signup successful"
}



Applied this too still facing problem

From what I see, this is not directly related to the user creation, if you provide the error log you may find it on the Error Log Doctype, I think we can have more clear understanding.

However, you may also check if you have any active hooks or workflows that’s run on User Insert, because from what I see the system is trying to access the Notification Settings using the currently logged in user (parsed from the request) and in this case it’s Guest, and this Doctype is not used on the provided code.

Another side note, for creating a New Doctype try to stick with Frappe recommendation using the frappe.new_doc(<doc_name>) instead.

def signup_user(email, password, name, phone)

your function takes name as argument

but you are writing first_name, `last_name` inside the function!

"first_name": first_name,
"last_name": last_name,

Resolved
flow
frappe.set_user(“Administrator”)

signup operation with try and except
in finally block
frappe.set_user(“Guest”)