Skip to content

Fix the sample progress and analyses count lagging by one analysis - #3058

Open
ramonski wants to merge 2 commits into
2.xfrom
fix/sample-progress-one-analysis-behind
Open

ramonski wants to merge 2 commits into
2.xfrom
fix/sample-progress-one-analysis-behind

Conversation

@ramonski

@ramonski ramonski commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

A sample counts its analyses from the catalog: getAnalysesNum reads the review state of each analysis from its brain, and getProgress is computed from that count. Both are catalog metadata on the sample, and the samples listing draws the progress bar from them.

An analysis promotes its submit and its verify to the sample from within its own after-transition event, which runs before the machinery that reindexes the analysis. The sample is therefore reindexed while the brain of the analysis that triggered it still carries the state it had before, and it stores a count and a progress that are one analysis behind.

The error is always the last analysis of a sample, which is the one that moves the sample, so it shows on every sample a laboratory ever submits or verifies.

Current behavior before PR

A verified sample with one analysis, read back from the catalog:

review_state:    verified
getAnalysesNum:  [0, 1, 0, 1]   # [verified, total, not_submitted, to_be_verified]
getProgress:     33

The analysis itself is verified and the sample is verified, but the sample's own metadata says nothing is verified and one analysis is still waiting. The progress bar reads 33% where the formula gives 66%. With two analyses it reads 60% instead of 80%.

Desired behavior after PR is merged

review_state:    verified
getAnalysesNum:  [1, 1, 0, 0]
getProgress:     66

And for two analyses, 80% verified and 40% submitted.

Why reindexing the state alone is enough

review_state is both a FieldIndex and a metadata column on every senaite catalog (BaseCatalog.INDEXES and COLUMNS), and the count is read from the metadata. reindexObject(idxs=["review_state"]) passes update_metadata=1 along with the index list, IndexQueue carries it through optimize(), and CatalogMultiplexProcessor.reindex hands it to _reindexObject. The brain the sample then reads is current, and nothing else about the analysis is reindexed twice.

The placement matters more than the scope. The queue merges the entries for one object at the position of that object's first entry, so reindexing the analysis after the sample has already been told about the transition is too late. It goes before anything is promoted.

Verification

  • A single-analysis sample taken through receive, submit and verify reports [1, 1, 0, 0] and 66%; a two-analysis sample reports [2, 2, 0, 0] and 80% verified, [0, 2, 0, 2] and 40% submitted. Before the change, 33%, 60% and 40%. Reproduced across several fresh instances.
  • bin/test-senaite -s senaite.core -t "Workflow*": 33 tests, 0 failures.
  • bin/test-senaite -s senaite.core -t "Analysis*": 42 tests, 0 failures.

A sample counts its analyses from the catalog: getAnalysesNum reads the
review state of each one from its brain, and getProgress is computed
from that count. Both are catalog metadata on the sample.

An analysis promotes its submit and its verify to the sample from
within its own after-transition event, which runs before the machinery
that reindexes the analysis. The sample is therefore reindexed while
the brain of the analysis that triggered it still carries the state it
had before, and it stores a count and a progress that are one analysis
behind.

A verified sample with a single analysis reports 33% instead of 66%,
and its analyses count reads "nothing verified, one waiting" although
the analysis is verified and the sample is not. With two analyses it
reports 60% instead of 80%. The error is the last analysis of each
sample, which is the one that moves the sample, so it shows on every
sample a laboratory ever submits or verifies.

Reindexing the state of the analysis before anything is promoted is
enough. review_state is both an index and a metadata column on every
senaite catalog, and reindexObject passes update_metadata=1 along with
the index list, which the queue carries and the catalog multiplex
processor honours, so the brain the sample then reads is current.
@ramonski
ramonski force-pushed the fix/sample-progress-one-analysis-behind branch from e494248 to 875df68 Compare October 10, 2026 08:45
@ramonski
ramonski requested a review from xispa October 10, 2026 09:15
@ramonski ramonski added the Bug 🐞 Something is broken label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug 🐞 Something is broken

Development

Successfully merging this pull request may close these issues.

1 participant