Skip to content

component: run checks on publish and update runs table #40

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0einstein0
Copy link
Member

❤️ Thank you for your contribution!

Description

Depends on #33 to be merged first

Partially closes inveniosoftware/invenio-rdm-records#2051

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.

Copy link
Member

@slint slint left a comment

Choose a reason for hiding this comment

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

Some minor comments, but the major one is the need for a refactor now that the _run_checks method has grown and is a bit difficult to read/parse.

latest_check = (
CheckRun.query.filter(
CheckRun.config_id == check_config.id,
CheckRun.record_id == record.id,
CheckRun.is_draft.is_(True),
CheckRun.is_draft.is_(record.is_draft),
Copy link
Member

Choose a reason for hiding this comment

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

See above, but this becomes especially confusing now. Is record a record or draft? We shouldn't rely on calling record.is_draft, it should be obvious/readable from the context we're in.

Comment on lines 145 to 150
def publish(self, identity, data=None, record=None, errors=None, **kwargs):
"""Run checks on publish."""
if errors is None:
errors = []

self._run_checks(identity, data, record, errors)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of the fact that we have one function that "does it all". Can you have a go at splitting _run_checks into something we can also start reusing e.g. in the requests "Checks" tab and/or the Request overrides we have in Zenodo for running checks on inclusion requests?

It might be that we actually don't want these to be in this component, but on an API or Service layer of checks.

Comment on lines 100 to 102
CheckRun.query.filter_by(
config_id=check_config.id, record_id=record.id, is_draft=True
).delete()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CheckRun.query.filter_by(
config_id=check_config.id, record_id=record.id, is_draft=True
).delete()
CheckRun.query.filter_by(record_id=record.id, is_draft=True).delete()

If we refactor this big function, we could just run the suggested version in the publish(...) handler. Even better we could also run an UDPATE to convert is_draft=True check runs to is_draft=False beforehand.

Comment on lines 66 to 69
def publish(self, identity, draft=None, record=None):
"""Run checks on publish."""
CheckRunAPI.delete_check_run(record_uuid=record.id, is_draft=False)
CheckRunAPI.run_checks(identity, is_draft=False, record=record)
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to test it again, it is not updating correctly now

@0einstein0
Copy link
Member Author

There is some issue with new draft save not showing errors

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.

Checks leftover tasks
2 participants