Skip to content

Avoid storing default user email if not fetching codes - #705

Closed
edan-bainglass wants to merge 1 commit into
masterfrom
default-user-email
Closed

Avoid storing default user email if not fetching codes#705
edan-bainglass wants to merge 1 commit into
masterfrom
default-user-email

Conversation

@edan-bainglass

@edan-bainglass edan-bainglass commented Sep 5, 2025

Copy link
Copy Markdown
Member

In #543, we opted to replacing direct default user fetching with fetching via the user's email, to avoid thread issues.
Since, #646 made code fetching optional in ComputationalResourcesWidget. However, the storing of the default user's email was no guarded. This PR remedies this.
#646 was introduced, as at least the in the QE app, which has moved towards MVC design, now handles its own code fetching.
However, it appears that even the storing of the default user's email introduces a threading issue (see aiidalab/aiidalab-qe#1391).

Note that this was discovered during development, in which I am threading the plugin fetching mechanism. Not yet clear where and how this leads to the bug. Investigating...

In any case, this PR simply completes the work of #646

@codecov

codecov Bot commented Sep 5, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.27%. Comparing base (bf7eb89) to head (40d4eec).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
aiidalab_widgets_base/computational_resources.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #705      +/-   ##
==========================================
- Coverage   84.29%   84.27%   -0.02%     
==========================================
  Files          18       18              
  Lines        3584     3587       +3     
==========================================
+ Hits         3021     3023       +2     
- Misses        563      564       +1     
Flag Coverage Δ
python-3.11 84.27% <80.00%> (-0.02%) ⬇️
python-3.9 84.28% <80.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

)

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.

@edan-bainglass

Copy link
Copy Markdown
Member Author

The issue does not appear to be a problem. I suspect it was an temporary error in implementation that is no longer in place. Closing for now.

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.

3 participants