Skip to content

Do not fail a validator when there is no form - #3050

Open
ramonski wants to merge 4 commits into
2.xfrom
fix/uncertainties-validator-without-request
Open

ramonski wants to merge 4 commits into
2.xfrom
fix/uncertainties-validator-without-request

Conversation

@ramonski

@ramonski ramonski commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

Four validators in bika/lims/validators.py read the value they check back out of the request. They have to, in a way: an Archetypes sub-field validator is handed one cell at a time, and the checks are about the record as a whole, so the validator looks the whole value up again by field name and runs once per submit.

That works for the edit form and nowhere else. Setting the field programmatically, through the JSON API or an import, leaves nothing in the form. Three of the four take the request with a default for a missing key, which does not help: whole-object validation passes REQUEST explicitly as None, so kwargs.get("REQUEST", {}) returns the None rather than the default, and the next line raises on it.

validator field reads
service_defaultresult_validator AnalysisService.DefaultResult request.get(...)
uncertainties_validator AnalysisService.Uncertainties request[...]
service_conditions_validator AnalysisService.Conditions request.get(...)
container_prepreservation_validator Container.PrePreserved request.form

Current behavior before PR

Creating an analysis service with a default result through the API:

{"portal_type": "AnalysisService", "title": "Colour", "Keyword": "Colour",
 "ResultType": "select",
 "ResultOptions": [{"ResultValue": "0", "ResultText": "colorless"}],
 "DefaultResult": "0"}
-> {"message": "No objects could be created: 'NoneType' object has no attribute 'get'"}

The same with uncertainty ranges, where the subscript raises a KeyError that reaches the client as a 500:

{"message": "'Uncertainties'", "type": "KeyError", "success": false}

Desired behavior after PR is merged

No form, nothing to check. The validator returns and leaves the value to the field, exactly as for a type whose records never pass through a browser.

Two lines each: kwargs.get("REQUEST") or {}, so an explicit None falls back to the empty mapping, and a guard before the value is read.

Verification

Reproduced on DefaultResult and on Uncertainties, both creating cleanly after the change and both still validated on the edit form, where the form carries the field and the validator still runs over every row.

The other two are the same two lines and are fixed in the same pass. service_conditions_validator turns out not to be reached on this path today, which the same probe shows, and container_prepreservation_validator belongs to the Archetypes Container. Neither was reproduced; both are included because leaving a known instance of a defect next to a fixed one is how it comes back.

The two validators that were already guarded, with kwargs.get("REQUEST") or {}, are untouched.

Full senaite.core test suite: 229 tests, 0 failures, 0 errors.

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

@ramonski
ramonski requested a review from xispa October 8, 2026 08:55
@ramonski ramonski added the Bug 🐞 Something is broken label Oct 8, 2026
Four validators read the value they check back out of the request,
because an Archetypes sub-field validator is handed one cell at a time
and the checks are about the record as a whole. Three of them took the
request with a default for a missing key, which does not help: whole
object validation passes REQUEST explicitly as None, so the default
never applies and the next line raises on it.

No form, nothing to check. They return and leave the value to the
field, exactly as for a type whose records never pass through a
browser.

Reproduced on the analysis service's DefaultResult, which refuses every
service with a default result set through the API or an import. The
uncertainties one does the same. The other two are the same two lines,
found by reading the file rather than by hitting them.
@ramonski
ramonski force-pushed the fix/uncertainties-validator-without-request branch from 0ee615c to 3ea6c44 Compare October 8, 2026 11:23
@ramonski ramonski changed the title Do not fail the uncertainties validator when there is no form Do not fail a validator when there is no form Oct 8, 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