IRecordModifiedEvent not triggered by script

I have a subscriber listening on IRecordModifiedEvent for a change to an entry in the registry. If you update the entry TTW, the subscriber works as expected.

But I have a script that gets run by a cronjob that updates the registry. Basically it is doing this:

registry = api.portal.get_tool('portal_registry')
departments = registry[myrecord]
# changes to departments dictionary here
registry.records[myrecord].value = departments
transaction.commit()

After it runs, I can look in the registry and see the new value. But the subscriber was not triggered.

Is there something I need to do differently, or is this a bug?

Ok, seems I was mistaken. The subscriber has some logger statements, which I was not seeing in the running instance, so I assumed the subscriber didn't run. Log messages don't show up in the script output but print statements do. So once I changed them to print statements, and I can see output now.

The subscriber still doesn't seem to work in this case, but that is a separate issue, unrelated to the topic.

1 Like

Ok, maybe it is somewhat related...

When the subscriber is run from the script, both event.oldValue and event.newValue have the new value, so I can't check for the difference :confused:

1 Like

SOLVED! This was insane...

When making a copy of the original registry entry for manipulation, I have to do a deepcopy(). Otherwise when I update my copy, it was also updating the registry entry without triggering the subscriber (and I didn't realize it was updating the registry at this point). So then when I was trying to actually change the registry entry, it had already been updated, so my subscriber wasn't seeing a change in value

2 Likes

Plone Foundation Code of Conduct