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

records: make do_finalise more robust and tolerate multiple commit messages #761

Open
GraemeWatt opened this issue Feb 25, 2024 · 0 comments
Assignees
Labels
complexity: medium priority: high type: bug Indicates an unexpected problem or unintended behaviour

Comments

@GraemeWatt
Copy link
Member

A problem was recently reported with version 2 of a record which failed to display because of multiple (10!) entries in the record_version_commit_message database table with the same recid and version. There were new Sentry events: MultipleResultsFound: Multiple rows were found when exactly one was required from the line:

commit_message = commit_message_query.one()

This situation could conceivably arise if do_finalise fails (for example, due to problems connecting to the database) after the commit message has been added to the database, but before setting hep_submission.overall_status = "finished". Eventually, after 10 duplicate commit messages had been added, it seems that the do_finalise function failed when reindexing.

The do_finalise function should be made more robust to catch possible exceptions due to temporary problems connecting to the database or OpenSearch, for example, by using db.session.rollback() to rollback changes to the database and by catching reindexing exceptions (similar to the try/except used for the admin_indexer immediately below). An exception should return an error to the user requesting that they try to finalise the record later. This is better than partially finalising the record with some steps missing.

Although it should not happen, the get_commit_message function could also be made more robust to tolerate multiple commit messages with the same recid and version, for example, by replacing the lines:

commit_message_query = RecordVersionCommitMessage.query \
.filter_by(version=ctx["version"], recid=recid)
if commit_message_query.count() > 0:
commit_message = commit_message_query.one()

with:

        commit_message_query = RecordVersionCommitMessage.query \
            .filter_by(version=ctx["version"], recid=recid).order_by(RecordVersionCommitMessage.id.desc())

        if commit_message_query.count() > 0:
            commit_message = commit_message_query.first()

to get the most recent commit message in case there are multiple entries in the database.

@GraemeWatt GraemeWatt added type: bug Indicates an unexpected problem or unintended behaviour priority: high complexity: medium labels Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: medium priority: high type: bug Indicates an unexpected problem or unintended behaviour
Projects
Status: To do
Development

No branches or pull requests

2 participants