Granting local roles to content created by anonymous

I have a public form that creates content in Plone 6.0.14 ClassicUI. After the item is created or modified, I have an event handler that tries to grant local roles to certain groups. My current code is something like:

# run for ISomeForm, IObjectAddedEvent, IObjectModifiedEvent

def set_form(context, event):
    with api.env.adopt_user(username="admin"):

        api.group.grant_roles(
            groupname="form_editors", roles=["Editor"], obj=context
        )

        api.group.grant_roles(
            groupname="form_verifiers", roles=["Reviewer"], obj=context
        )
        context.reindexObject()
        context.reindexObjectSecurity()
        
        #wf = api.portal.get_tool(name="portal_workflow")
        #wf_chain = wf.getWorkflowsFor(context)
        #owf = wf_chain[0]
        #owf.updateRoleMappingsFor(context) <-- returns 0

Even without adopting to the admin user (code is running as anonymous user), the above code sets the roles. However, the actual role to permission mapping is not set so group members do not actually gain local roles. I have also tried using the updateRoleMappingsFor method of the workflow tool but I am not sure how to use it.

I would appreciate suggestions on how to do the above or to get hints on what could be the problem.

Update:
My original code was working fine except I was using the plural form to reference my group name. My actual registered group names are singular. I did not need to use api.env.adopt_user

form_editorS should just be form_editor
form_verifierS should just be form_verifier

:person_facepalming: