-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix threading issue when accessing user instance in _get_codes of ComputationalResourceWidgets #543
Fix threading issue when accessing user instance in _get_codes of ComputationalResourceWidgets #543
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #543 +/- ##
=======================================
Coverage 87.12% 87.12%
=======================================
Files 27 27
Lines 4643 4646 +3
=======================================
+ Hits 4045 4048 +3
Misses 598 598
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
6ced438
to
98c52a4
Compare
98c52a4
to
ffe8117
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very confused. How do your proposed changes fix the issue that you saw in the QeApp?? What is the root cause here?
This is the part of traceback that lead me to the change, if you remember the change we made from migrate aiida-core v1->v2, that the aiida nodes in the traits are replaced by uuid, the issue aiidalab/aiidalab-qe#582 has the same source of problem.
The So if AiiDA still not threading safe, we need to implement a rule for all the widgets development in AiiDAlab that the node should have the local scope not cross the functions to avoid the problem. If the changes I made here are correct, we now know two proper design principles to follow:
|
@sphuber would you mind taking a look if the changes here make sense? I am not super familiar in how aiida-core handles User instances. |
I had a look but I don't understand what the changes to fetching the default user should do. First of, If you want to manually query for a user given an email, I would recommend |
@sphuber thanks! Yes, |
Tested, works good! I update the PR. @danielhollas |
@unkcpz just to double-check. This PR fixes the threading issue that you saw in QeApp and reported at aiidalab/aiidalab-qe#582 (tl;dr, you were seeing
Oh, the caching then explains our threading issues! That's a really unfortunate side-effect, but now I understand why the fix in this PR works. Even though we were calling One can verify this in user = User.collection.get_default()
user2 = User.collection.get_default()
id(user) == id(user2)
> True whereas node = load_node(117419)
node2 = load_node(117419)
id(u) == id(u2)
> False @unkcpz can you check if we use I also wonder if |
AiiDA has never been thread-safe, so I am not sure if we should start making off the cuff fixes for just this. There are plenty of other singletons in the code, such as the loaded |
That's fair, although I'd argue that there is still a slight difference here. In general, I think the issue we have in AWB is that we have a coupling between the code that handles the frontend events (i.e. user clicking a ipywidgets button), which generally come from different threads, and backend code that communicates with the DB. This coupling makes it hard to see where the footguns lie. |
@unkcpz there are two other instances of
I am not sure this is the correct solution here, feels more like a hack. We really want the default user. What if there are two users with the same email (is that possible?). |
Sure, that's fair. It is at least documented in the
That is what |
I guess that is indeed because you are directly using the Python API. If there were a full-fledged web API (e.g. REST API) that exposed all necessary functionality, then it might be a better solution to use that instead. There is the REST API implemented in |
Oh, perfect, that's good to know. In that case I am happy with this PR as along as the other uses are fixed as well.
That is very exciting, thanks! |
Thanks for the discussion!
Yes, in the long term this is the way we should go. We did some test before with the workflow viewer and it is definitely doable. But it requires also some test on how AiiDAlab handle the restapi service etc. and effort of changing things from using aiida node directly to restapi call little by little for AWB and other apps.
Cool! Looking forward to it. In AiiDAlab, we can start test on moving to restapi in parallel. |
@danielhollas the other two cases are also changed, thanks a lot for the careful review! |
fixes aiidalab/aiidalab-qe#582
The
_get_codes
method is used in the multi-threading case by QEapp, and causes the issue. Since we assume one AiiDAlab app instance is bound with the default user, there is no need to restrict it again in the code queries.This fix will not change any actual behavior.
Interestingly, the fix also reveals an incorrect test which should fail but somehow not.