Skip to content

[#746] can now give (repl) row result sort function in DataObject constructor #747

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions irods/data_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ def __repr__(self):

class iRODSDataObject:

def __init__(self, manager, parent=None, results=None):
def __init__(self, manager, /, parent=None, results=None, *, results_sort_key = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the / break this interface? In other words, if a client is calling this with manager as a keyword argument, will this cause it to experience errors? I doubt anybody is doing that, but just curious since this will be going into a minor release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that usage would break, but there's no reason we can't include manager as an optional-keyword arg. good eye!

self.manager = manager
if parent and results:
self.collection = parent
if results_sort_key is None:
results_sort_key = lambda r: r[DataObject.replica_number]
results = sorted(results, key=results_sort_key)
for attr, value in DataObject.__dict__.items():
if not attr.startswith("_"):
try:
Expand All @@ -58,7 +61,6 @@ def __init__(self, manager, parent=None, results=None):
# backward compatibility with older schema versions
pass
self.path = self.collection.path + "/" + self.name
replicas = sorted(results, key=lambda r: r[DataObject.replica_number])
self.replicas = [
iRODSReplica(
r[DataObject.replica_number],
Expand All @@ -72,7 +74,7 @@ def __init__(self, manager, parent=None, results=None):
create_time=r[DataObject.create_time],
modify_time=r[DataObject.modify_time],
)
for r in replicas
for r in results
]
self._meta = None

Expand Down
3 changes: 2 additions & 1 deletion irods/manager/data_object_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def get(
a path in the local filesystem to use as a destination file).
"""
parent = self.sess.collections.get(irods_dirname(path))
_results_sort_key = options.pop('results_sort_key', None)

# TODO: optimize
if local_path:
Expand Down Expand Up @@ -300,7 +301,7 @@ def get(
results = query.all() # get up to max_rows replicas
if len(results) <= 0:
raise ex.DataObjectDoesNotExist()
return iRODSDataObject(self, parent, results)
return iRODSDataObject(self, parent, results, results_sort_key = _results_sort_key)

def put(
self,
Expand Down