Hello,
I am having trouble with the same issue. It seems to me that pep_api_atomic_apply_metadata_operations_post is not consistent in terms of serialized objects (parameters - referring the earlier discussion as well).
Pep loaded into core.py
def pep_api_atomic_apply_metadata_operations_post(rule_args, callback, rei):
var_map = session_vars.get_map(rei)
username = var_map["client_user"]["user_name"]
obj = str(rule_args[2].buf)
print obj
Logs:
{"operations": [{"attribute": "atr1", "operation": "add", "value": "val1"}, {"attribute": "atr2", "operation": "add", "value": "val2"}, {"attribute": "atr3", "operation": "add", "value": "val3"}], "entity_name": "/u0137480_instance1/home/redcap/destination/records_20220906_1038.csv", "entity_type": "data_object"}
I would like to somehow catch the object path which is the value of "entity_name". But I couldnt succeed this in a reliable way.
Client script:
import os, os.path
from irods.session import iRODSSession
from irods.meta import iRODSMeta, AVUOperation
avus = [('atr1', 'val1'), ('atr2', 'val2'), ('atr3', 'val3')]
env_file = os.getenv('IRODS_ENVIRONMENT_FILE', os.path.expanduser('~/.irods/irods_environment.json'))
with iRODSSession(irods_env_file=env_file) as session:
obj = session.data_objects.get("/u0137480_instance1/home/redcap/destination/records_20220906_1038.csv")
obj.metadata.apply_atomic_operations(*[AVUOperation(operation='add', \
avu=iRODSMeta("{}".format(str(meta[0])), "{}".format(str(meta[1])))) for meta in avus])
The type of rule_args[2].buf is <class 'irods_types.char_array'>. And if I want to convert it to json object to be able to catch the path easily, then I am having the errors below:
Pep loaded into core.py
import json
def pep_api_atomic_apply_metadata_operations_post(rule_args, callback, rei):
var_map = session_vars.get_map(rei)
username = var_map["client_user"]["user_name"]
obj = str(rule_args[2].buf)
obj_dict = json.loads(obj)
print obj_dict
Errors in the client side:
Traceback (most recent call last):
File "test.py", line 11, in <module>
avu=iRODSMeta("{}".format(str(meta[0])), "{}".format(str(meta[1])))) for meta in avus])
File "/usr/lib/python2.7/site-packages/irods/meta.py", line 118, in apply_atomic_operations
self._manager.apply_atomic_operations(self._model_cls, self._path, *avu_ops)
File "/usr/lib/python2.7/site-packages/irods/manager/metadata_manager.py", line 176, in apply_atomic_operations
self._call_atomic_metadata_api(request)
File "/usr/lib/python2.7/site-packages/irods/manager/metadata_manager.py", line 183, in _call_atomic_metadata_api
response = conn.recv()
File "/usr/lib/python2.7/site-packages/irods/connection.py", line 132, in recv
raise get_exception_by_code(msg.int_info, err_msg)
irods.exception.UnknowniRODSError: None
Errors in the server:
rsyslogd stdout | 2022-09-07T15:52:58.596142+02:00 dev-u0137480-instance1 rodsServer[715476]: u0137480_instance1 - remote addresses: 10.0.2.100, 2a02:2c40:0:51:177:0:9:2ca7 ERROR: caught python exception: Traceback (most recent call last):#012 File "/etc/irods/rules_numa.py", line 64, in pep_api_atomic_apply_metadata_operations_post#012 obj_dict = json.loads(obj)#012 File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads#012 return _default_decoder.decode(s)#012 File "/usr/lib64/python2.7/json/decoder.py", line 369, in decode#012 raise ValueError(errmsg("Extra data", s, end, len(s)))#012ValueError: Extra data: line 1 column 315 - line 1 column 330 (char 314 - 329)
Could you try this? And please let me know if you think I am missing something.
Thanks.
Regards,
Mustafa