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

bug: add handler for handling changed domain #500

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

carlinmack
Copy link
Contributor

@carlinmack carlinmack commented Nov 6, 2024

❤️ Thank you for your contribution!

(Part of) Close inveniosoftware/invenio-app-rdm#2777

Description

Please describe briefly your pull request.

We call mark_changed but we did not check that it handled Domains

Calling flush as similarly done in the pre-commit hook

Also remove setting of role.id as the added flush() will add the ID from DB

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

invenio_accounts/datastore.py Outdated Show resolved Hide resolved
@@ -73,11 +73,16 @@ def commit(self):

def mark_changed(self, sid, uid=None, rid=None, model=None):
"""Save a user to the changed history."""
# needed so that we have the id from the DB on the model
self.db.session.flush()
Copy link
Member

Choose a reason for hiding this comment

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

@slint Can you have a look at the impact of having a flush here.

Copy link
Member

Choose a reason for hiding this comment

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

I see we very often tiptoe around flushes, and get them in implicitly just by chance because we perform another SELECT query down the line, e.g.:

domain = Domain.create(...)

# ...in another function...

user = UserAggregate.get(...)  # <-- this triggered a flush, so our `domain`
                               #     from above now has a `domain.id`

So I think it's better to be explicit about it, which is what calling mark_changed also implies (i.e. that something will be persisted to the DB).

@carlinmack is also checking this change on tests across other repos to see if there are wrong expectations.

remove setting of role.id as the added flush() will add the ID from DB
@carlinmack carlinmack force-pushed the commit-domain branch 2 times, most recently from 6f9ad3c to b8ae274 Compare November 7, 2024 09:53
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.

Domains: Existing Domains Not Visible on Admin Page After Login
4 participants