Skip to content
Closed
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: 6 additions & 2 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def __init__(
self.refresh, names=["allow_disabled_computers", "allow_hidden_codes"]
)

self._default_user_email = orm.User.collection.get_default().email
if fetch_codes:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you explain the logic? Why only store the _default_user_email conditionally? Is there any side effect to always storing_default_user_email?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The side effect was that an error was raised by trying to access the User table. I suspect this was being accessed by a thread other than the main one, which should not happen.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But we're not holding a pre-existing connection here, so even if there was another thread accessing this data it should not be a problem I think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, unless the get_default method is cached. In that case a better solution is to use a lock here imo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

    @property
    def default_user(self) -> Optional['User']:
        """Return the default user for the profile, if it has been created.

        This is cached, since it is a frequently used operation, for creating other entities.
        """

Cached 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, now I vaguely remember that we had the same issue in QeApp with this method, might be good to how it is solved there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's all discussed in the referenced PR - #543. But I don't think the ComputationalResourcesWidget was run on a thread there. Not sure. But yeah, good to have another look, when time permits 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But I don't think the ComputationalResourcesWidget was run on a thread there.

I don't think you can generally guarantee that another thread will not run at the same time --- AWB is a library so we don't control how it is used. I agree it would be good to ultimately resolve this one way or the other. (but also I am sure there are many other issues like this in other widgets unfortunately.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think a general solution was already proposed. Stop using threads - implement and use a proper REST API.

self._default_user_email = orm.User.collection.get_default().email

selection_row = ipw.HBox(
children=[
Expand Down Expand Up @@ -138,7 +139,10 @@ def __init__(

def _get_codes(self):
"""Query the list of available codes."""
user = orm.User.collection.get(email=self._default_user_email)
if hasattr(self, "_default_user_email"):
user = orm.User.collection.get(email=self._default_user_email)
else:
user = orm.User.collection.get_default()

filters = (
{"attributes.input_plugin": self.default_calc_job_plugin}
Expand Down