Skip to content

Add data integrity check for investigation - #4216

Open
stacktraceghost wants to merge 6 commits into
mainfrom
check-investigation-state
Open

stacktraceghost wants to merge 6 commits into
mainfrom
check-investigation-state

Conversation

@stacktraceghost

@stacktraceghost stacktraceghost commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Related to #4172

After investigating several scenarios, it showed that are_results_complete_for_committee_session passed a definitive result which was still linked to a polling station in a next session, while not having an investigation.

The suggestion was made to add a data integrity check to that function. However, we found that extending two existing match arms would cover these cases during the entire process instead of only at the end.

How to test

  • Tests should succeed

Since this fix is based upon #4190 which contains the initial bugfix, you can only trigger the panic by locally:

  1. Creating an investigation, conclude corrected_results=yes (this also creates and links a data entry)
  2. Setting the investigation_state for that polling station to NULL in the database
    Result: a panic will occur when you try to access that election through the frontend. Other invalid combinations should do this too.

Reviewer notes

  • It is not possible anymore to retrieve a polling station in an invalid state. For example in switch_to_without_new_results, the polling station cannot be retrieved after deleting the data entry but not yet updating the investigation to the correct state.
  • link_data_entry: return was removed during one of our iterations. We do not use the returned value anywhere.
  • Question: should we still add another check to the query?

@stacktraceghost stacktraceghost added the backend Issues or pull requests that relate to the backend label Oct 30, 2026
@stacktraceghost
stacktraceghost requested a review from a team as a code owner October 30, 2026 12:16
@stacktraceghost stacktraceghost added the needs-backport/1.2 Needs backporting to the 1.2 release branch label Oct 30, 2026
@stacktraceghost
stacktraceghost changed the base branch from main to 4172-investigation-delete-readd October 30, 2026 12:16
oliver3
oliver3 previously approved these changes Oct 30, 2026
Comment thread backend/src/domain/investigation.rs Outdated
// No investigation, there must not be a data entry ID
(None, None) => None,
// All other situations, panic
_ => panic!("Unexpected data entry ID for investigation status"),

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 think this should return a DataIntegrityError instead of panicking

@stacktraceghost stacktraceghost Nov 2, 2026 •

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.

Rebased due to change of base branch.

Went through a puzzle with the errors, split the steps in 3 commits:

... and some clippy fixes (ref log)

Base automatically changed from 4172-investigation-delete-readd to main November 2, 2026 09:34
@praseodym
praseodym dismissed oliver3’s stale review November 2, 2026 09:34

The base branch was changed.

This branch was successfully deployed

1 active deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Issues or pull requests that relate to the backend needs-backport/1.2 Needs backporting to the 1.2 release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants