Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does iRODSMetaCollection object have no get attribute? #634

Open
tanmayagrawal21 opened this issue Sep 30, 2024 · 1 comment
Open

How does iRODSMetaCollection object have no get attribute? #634

tanmayagrawal21 opened this issue Sep 30, 2024 · 1 comment

Comments

@tanmayagrawal21
Copy link

tanmayagrawal21 commented Sep 30, 2024

{"ansible_loop_var": "item", "changed": false, "item": "/testing/trash/home/shared", "msg": "An unexpected exception of type AttributeError occurred. Arguments: (\"'iRODSMetaCollection' object has no attribute 'get'\",)"}

Source Python

    elif entity_type == "collection":
        try:
            return session.collections.get(entity_name)
        except CollectionDoesNotExist as e:
            raise _IrodsAvuError(
                "The collection '{0}' does not exist".format(entity_name))

Despite it being one of the stated functionalities:
https://github.com/irods/python-irodsclient/blob/main/irods/test/collection_test.py

@alanking
Copy link
Contributor

iRODSMetaCollection does not appear to have a get attribute:

class iRODSMetaCollection(object):
def __call__(self, admin = False, timestamps = False, **opts):
x = copy.copy(self)
x._manager = (x._manager)(admin, timestamps, **opts)
x._reset_metadata()
return x
def __init__(self, manager, model_cls, path):
self._manager = manager
self._model_cls = model_cls
self._path = path
self._reset_metadata()
def _reset_metadata(self):
self._meta = self._manager.get(self._model_cls, self._path)
def get_all(self, key):
"""
Returns a list of iRODSMeta associated with a given key
"""
if six.PY2:
if isinstance(key, unicode):
key = key.encode('utf8')
else:
if isinstance(key, bytes):
key = key.decode('utf8')
if not isinstance(key, str):
raise TypeError
return [m for m in self._meta if m.name == key]
def get_one(self, key):
"""
Returns the iRODSMeta defined for a key. If there are none,
or if there are more than one defined, raises KeyError
"""
values = self.get_all(key)
if not values:
raise KeyError
if len(values) > 1:
raise KeyError
return values[0]
def _get_meta(self, *args):
if not len(args):
raise ValueError(
"Must specify an iRODSMeta object or key, value, units)")
return args[0] if len(args) == 1 else iRODSMeta(*args)
def apply_atomic_operations(self, *avu_ops):
self._manager.apply_atomic_operations(self._model_cls, self._path, *avu_ops)
self._reset_metadata()
def set(self, *args, **opts):
"""
Set as iRODSMeta to a key
"""
meta = self._get_meta(*args)
self._manager.set(self._model_cls, self._path, meta, **opts)
self._reset_metadata()
def add(self, *args, **opts):
"""
Add as iRODSMeta to a key
"""
meta = self._get_meta(*args)
self._manager.add(self._model_cls, self._path, meta, **opts)
self._reset_metadata()
def remove(self, *args, **opts):
"""
Removes an iRODSMeta
"""
meta = self._get_meta(*args)
self._manager.remove(self._model_cls, self._path, meta, **opts)
self._reset_metadata()
def items(self):
"""
Returns a list of iRODSMeta
"""
return self._meta
def keys(self):
"""
Return a list of keys. Duplicates preserved
"""
return [m.name for m in self._meta]
def __len__(self):
return len(self._meta)
def __getitem__(self, key):
"""
Returns the first iRODSMeta defined on key. Order is
undefined. Use get_one() or get_all() instead
"""
values = self.get_all(key)
if not values:
raise KeyError
return values[0]
def __setitem__(self, key, meta):
"""
Deletes all existing values associated with a given key and associates
the key with a single iRODSMeta tuple
"""
self._delete_all_values(key)
self.add(meta)
def _delete_all_values(self, key):
for meta in self.get_all(key):
self.remove(meta)
def __delitem__(self, key):
"""
Deletes all existing values associated with a given key
"""
if not isinstance(key, str):
raise TypeError
self._delete_all_values(key)
self._reset_metadata()
def __contains__(self, key):
if not isinstance(key, str):
raise TypeError
values = self.get_all(key)
return len(values) > 0
def remove_all(self, **opts):
for meta in self._meta:
self._manager.remove(self._model_cls, self._path, meta, **opts)
self._reset_metadata()
Are you looking for get_all or get_one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants