Skip to content

fix(ep_approval): Fix error handling, add test for single record flow - #917

Merged
zzacharo merged 1 commit into
CERNDocumentServer:masterfrom
sakshamarora1:fix/ep_approval
Sep 4, 2026
Merged

fix(ep_approval): Fix error handling, add test for single record flow#917
zzacharo merged 1 commit into
CERNDocumentServer:masterfrom
sakshamarora1:fix/ep_approval

Conversation

@sakshamarora1

Copy link
Copy Markdown
Contributor

Fixes: #912
Also makes the code ready for the migration script: https://gitlab.cern.ch/cds-team/production_scripts/-/merge_requests/59
Related: #908

Comment thread site/cds_rdm/components.py Outdated
Comment thread site/cds_rdm/components.py Outdated
Comment thread site/cds_rdm/components.py Outdated
return False
# Migrated case: both flags point at the same version, so only the current version carries apprn
if approved_internal == source_internal:
return record["id"] == source_internal

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.

If I understand correctly, that wil regenerate the apprn only for the accepted version. The truth is that all the newer versions should have the apprn number

@kpsherva kpsherva moved this to In review 🔍 in Sprint Q3 2026 ☀️ Aug 19, 2026
@zzacharo
zzacharo force-pushed the fix/ep_approval branch 6 times, most recently from 45d3d5d to 963cbe9 Compare September 2, 2026 10:00
pf["committee_approval"] = {
**ea,
"approved_public_version": new_record_id,
"source_public_version": src_id,

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.

do we have documentation describing these keys?

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.

I will add some documentation in our internal docs

def _validate_identifier_changes(self, identity, data, record, errors):
"""Raise ValidationError if a non-system identity modifies apprn."""
if identity.id == system_user_id:
return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't this raise instead of return to keep inline with the docstring?

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 return if the user is system. We raise for non-system users as per docstring, do I miss something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I mis-read, sorry!
But maybe we can have some kind of warning or log with the return, because the main bug might still happen if this component gets triggered by the system user either via a script or separately maybe due to a support ticket, and we don't return silently. WDYT?

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.

wasn't a test added to test the fix of the initial bug?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I missed adding it before, we should add it.

Comment thread .invenio
author_email = info@cds-rdm.com
year = 2022
python_version = 3.9
python_version = 3.14

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this leftover?

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.

I am not sure if we are still using that, but I upgraded locally to 3.14 and upgraded the information there too.

Comment thread pyproject.toml Outdated
"fastjsonschema<2.22",
"invenio-assets<4.2.5"
"invenio-assets<4.2.5",
"flask-caching>=2.3.0,<2.5.0"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it related to this PR?

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.

there is a separate commit pinning flask-cahcing, because tests were failing but it might be a leftover, I will check thanks!

@zzacharo
zzacharo force-pushed the fix/ep_approval branch 4 times, most recently from 374fe8c to 7803c6b Compare September 3, 2026 14:00
apprn = [{"scheme": "apprn", "identifier": rn} for rn in reportnumbers]
new_identifiers = apprn + not_apprn
else:
new_identifiers = not_apprn

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.

if the record does not have a committee_approval field then the identifiers are getting stripped out. That means, we need in the migration to populate the custom_field. This will be taken into account when running the https://gitlab.cern.ch/cds-team/production_scripts/-/merge_requests/59 and during migration.

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.

Shall we raise a validation error or warning when for some reason the committee_approval field is missing but apprn identifiers were passed instead of stripping them out? @kpsherva @palkerecsenyi @sakshamarora1

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.

yes

@zzacharo

zzacharo commented Sep 3, 2026

Copy link
Copy Markdown
Contributor
Screenshot 2026-09-03 at 17 00 51

- Fix error handling and add test for single-record flow.
- Add back cdsrn validation on identifiers.
- Change committee_approval.reportnumber from a string to a list of
  strings; it is now the single source of truth for apprn metadata
  identifiers on every edit/publish via _regenerate_apprn_identifier.
- Accept action writes [report_number]; views.py passes the list
  through and joins it for inclusion-request comments.
- CommitteeApproval.js and RecordVersionItem.js render the list joined
  with ", "; step guards use .length.
- detail.html collects all apprn identifiers via selectattr/join.
- Revert incorrect draftRecordId !== record.id guard from CommitteeApproval.js.
- invenio.cfg: use always_valid for apprn so migrated identifiers are
  not rejected on subsequent edits.
- Fix pre-existing test failures: grant origin format (uuid → pid_version_index)
  and wrong referee-grant scope assertions.

Co-Authored-By: Saksham <sakshamarora1001@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@sakshamarora1 sakshamarora1 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM!
Screenshot 2026-09-04 at 16 15 38

@zzacharo
zzacharo merged commit 93cad0a into CERNDocumentServer:master Sep 4, 2026
3 checks passed
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.

Bug: Manually added Approval report number vanishes when admin saves

3 participants