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

Deprecate Profile.repository_path #5516

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented May 4, 2022

Fixes #5513

The Profile.repository_path was historically used to give the absolute
filepath to the file repository on the local file system. However, this
is a property of the storage backend and not all backends will have this.
So instead of being generic to all profiles, this should be a storage
specific setting.

The property is deprecated and the functionality is added to the new
PsqlDosBackend.filepath_container. This forwards to the same property
but on the PsqlDostoreMigrator that has the actual implementation. The
reason for this is because the migrator needs to get the repository
location in the migrate method, but that needs to remain a
classmethod. The alternative of having the migrator call the property on
the backend, would require the backend to be passed to the constructor
of the migrator, but this won't work as the migrator also needs to be
constructed in the constructor of the backend, leading to an infinite
regression.

There is a also a slight difference in the implementation of the new
property. It returns the path of the disk object store container, which
is a subfolder of the original repository path. Old invocations of
profile.repository_path should therefore be replaced with
backend.filepath_container.parent.

Currently based on and blocked by #5496

@sphuber sphuber force-pushed the fix/5513/deprecate-profile-repository-path branch 3 times, most recently from 1bdb698 to e1a3cb8 Compare May 13, 2022 13:20
@ramirezfranciscof
Copy link
Member

The property is deprecated and the functionality is added to the new
PsqlDosBackend.filepath_container. This forwards to the same property
but on the PsqlDostoreMigrator that has the actual implementation. The
reason for this is because the migrator needs to get the repository
location in the migrate method, but that needs to remain a
classmethod. The alternative of having the migrator call the property on
the backend, would require the backend to be passed to the constructor
of the migrator, but this won't work as the migrator also needs to be
constructed in the constructor of the backend, leading to an infinite
regression.

Mmm I understand the technical rationale behind this, but I feel like it is a bit obfuscating to have the implementation in the PsqlDostoreMigrator. This smells a bit like there is an improvement to be made in the interaction/interface between these two classes.

Probably this is not the ideal solution, but as an alternative that at least does not make the interweaving of these more complex, could we maybe pass the filepath_container as an argument for the migrate method and keep the implementation in PsqlDosBackend?

@sphuber
Copy link
Contributor Author

sphuber commented May 13, 2022

Mmm I understand the technical rationale behind this, but I feel like it is a bit obfuscating to have the implementation in the PsqlDostoreMigrator. This smells a bit like there is an improvement to be made in the interaction/interface between these two classes.

That's what I tried initially. I tried to decouple this and make the migrator take an instance of the backend, but that won't work for now as the backend needs to be validated as it is constructed, for which it needs the migrator, and so there is a circular dependency. I discussed with @chrisjsewell and for now there is not better quick solution without a big refactoring of the backend/migrator.

Probably this is not the ideal solution, but as an alternative that at least does not make the interweaving of these more complex, could we maybe pass the filepath_container as an argument for the migrate method and keep the implementation in PsqlDosBackend?

Don't think this will work because if you look at the code, it is not just in Migrator.migrate that the path it is needed. It is actually retrieved in various places through the migrator instance that is passed around. Not sure if that would make it any cleaner.

@ramirezfranciscof
Copy link
Member

Right, I was not suggesting you do the refactoring now, but perhaps it would be a good time to open an issue documenting a bit the intricacy of the problem since you have just clashed with it and have the details fresh in your head.

In any case, I think I'll remove myself from the reviewers because it seems a lot of contextual information about these classes is needed to do a good review of the changes.

@ramirezfranciscof ramirezfranciscof removed their request for review May 16, 2022 08:44
Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

Sorry, but there is no way I'm excepting this in the current form.
Among other things, make filepath_container a static/standalone function, there is absolutely no need for it to be dependent on instances of the Migrator or StorageBackend, it only depends on the profile

@sphuber
Copy link
Contributor Author

sphuber commented May 16, 2022

Among other things, make filepath_container a static/standalone function, there is absolutely no need for it to be dependent on instances of the Migrator or StorageBackend, it only depends on the profile

How so? Its implementation comes from the PsqlDosBackend so why doesn't it make sense to have it be a method on that class?

@chrisjsewell
Copy link
Member

so why doesn't it make sense to have it be a method on that class?

Because you are massively overcomplicating a simple function that turns a string into a path, and passing around classes where they don't need to be passed

@sphuber sphuber force-pushed the fix/5513/deprecate-profile-repository-path branch from e1a3cb8 to 0b9cc23 Compare May 17, 2022 18:37
@sphuber sphuber requested a review from chrisjsewell May 17, 2022 18:38
@sphuber
Copy link
Contributor Author

sphuber commented May 17, 2022

There @chrisjsewell I have turned it into a function. Should be good now

@sphuber sphuber force-pushed the fix/5513/deprecate-profile-repository-path branch 2 times, most recently from 677bd7d to b82351a Compare May 19, 2022 08:38
@sphuber
Copy link
Contributor Author

sphuber commented Jul 8, 2022

Want to still review this @chrisjsewell ? Otherwise I'll merge it

giovannipizzi
giovannipizzi previously approved these changes Jul 13, 2022
Copy link
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

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

This now seems OK to me!

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

Thanks @sphuber, this looks much better, just one nitpick

aiida/storage/psql_dos/backend.py Outdated Show resolved Hide resolved
The `Profile.repository_path` was historically used to give the absolute
filepath to the file repository on the local file system. However, this
is a property of the storage backend and not all backends will have this.
So instead of being generic to all profiles, this should be a storage
specific setting.

The property is deprecated and the functionality is added to a new function
`aiida.storage.psql_dos.backend.get_filepath_container`. We considered
adding it as a property on the `PsqlDosBackend` class, which makes the
most sense semantically, but that made the code more complex than ideal.
The reason for this is because the property needs to be accessed both
from the backend as well as the associated migrator. However, the migrator
cannot have a reference to the backend since the migrator is used to
validate the backend class in its constructor, which would lead to a
circular dependence. The alternative of implementing the property on the
migrator and exposing it on the backend was possible, but also slightly
convoluted. The root of this problem is the limitation in the current
design that the migrator cannot have a reference to the storage backend
to which it belongs, but this should be addressed in another commit.

There is a also a slight difference in the implementation of the new
function. It returns the path of the disk object store container, which
is a subfolder of the original repository path. Old invocations of
`profile.repository_path` should therefore be replaced with
`get_filepath_container(profile).parent`.
@sphuber sphuber force-pushed the fix/5513/deprecate-profile-repository-path branch from 1ed234b to dc16d11 Compare July 14, 2022 18:43
@sphuber sphuber merged commit cffeacd into aiidateam:main Jul 14, 2022
@sphuber sphuber deleted the fix/5513/deprecate-profile-repository-path branch July 14, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate the Profile.repository_path property
4 participants