Skip to content

Let a reference sample inherit the expected values of its definition - #3056

Open
ramonski wants to merge 4 commits into
2.xfrom
fix/referencesample-inherits-definition-results
Open

ramonski wants to merge 4 commits into
2.xfrom
fix/referencesample-inherits-definition-results

Conversation

@ramonski

@ramonski ramonski commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

A reference sample points at the reference definition it was bought against. The definition carries the expected values, and those values decide which analysis services the sample supports.

Current behavior before PR

The values are copied from the definition to the sample by the edit form adapter, in the browser, on the modified event of the ReferenceDefinition field (senaite/core/browser/form/adapters/referencesample.py). Nothing on the server does it.

A reference sample created any other way therefore links a definition and holds no expected values:

  • over the JSON API
  • from a setup data import
  • by api.create
  • by copying one in the ZMI

getSupportedServices reads the expected values, so such a sample supports no service. On a worksheet it is listed under Add Blank / Add Control with an empty Supported Services column, and selecting it adds no reference analysis. The sample looks complete everywhere else: it has a definition, a lot number, an expiry date.

Desired behavior after PR is merged

ReferenceSample.getReferenceResults falls back to the definition when the sample holds no values of its own. Values set on the sample still win, and clearing them hands the sample back to its definition.

This is the behaviour getHazardCategories in the same class already has, twenty lines further down, and for the same reason.

Nothing about the edit form changes. A sample saved through it keeps its own copy of the values, as before.

Verification

A new doctest, ReferenceSampleFromDefinition.rst, covers the three cases: a sample that inherits, a sample whose own values win, and a sample with neither a definition nor values of its own.

Without the fix it fails on the first assertion; with it, it passes.

Run alongside the reference and QC doctests that read the same accessor, all green:

ReferenceSampleFromDefinition             Ran 1 tests with 0 failures
WorksheetAddReferenceSamples              Ran 1 tests with 0 failures
WorkflowReferenceAnalysisBlankSubmit      Ran 1 tests with 0 failures
WorkflowReferenceAnalysisControlSubmit    Ran 1 tests with 0 failures
QCAnalysesWithInterimFieldsOnAWorksheet   Ran 1 tests with 0 failures
API_analysis                              Ran 2 tests with 0 failures
InstrumentResultsImport                   Ran 1 tests with 0 failures

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

The expected values decide which services a reference sample supports,
and a sample that supports none is offered on a worksheet as a control
that adds no analysis.

They were copied from the definition by the edit form, in the browser,
as soon as the definition was picked. A sample made any other way, over
the API or from a setup data import, kept the link to its definition
and no values at all.

The accessor now falls back to the definition when the sample holds no
values of its own, which is what the hazard categories of the same
class already do.
@ramonski
ramonski requested a review from xispa October 9, 2026 09:09
@ramonski ramonski added the Bug 🐞 Something is broken label Oct 9, 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