Skip to content

[FORMAT] Fix 'required'/'fdr_type' attributes parsed into the wrong variable - #9764

Merged
timosachsenberg merged 1 commit into
developfrom
fix/9763-paramxml-required-attribute
Jul 20, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
fix/9763-paramxml-required-attribute

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9763.
Also fixes #9766 (the XQuest defect below, filed separately after review flagged it as out of scope for #9763).

Two instances of the same defect shape: an optionalAttributeAs*_ call whose output argument is a different variable than the one declared for it. Since optionalAttributeAsString_ leaves its output untouched when the attribute is absent (XMLHandler.h#L422-L431), the stale value of a previously parsed attribute is what ends up being tested.

1. ParamXMLHandler, ITEM branch — #9763

 //required
 std::string required_string;
-optionalAttributeAsString_(advanced_string, attributes, "required");
-if (advanced_string == "true")
+optionalAttributeAsString_(required_string, attributes, "required");
+if (required_string == "true")

An <ITEM advanced="true"> that omits the optional required attribute is silently tagged required. The ITEMLIST branch — added one day later in fc5ce40ece, "[FIX] addendum to [11567], fixed handling of item lists" — already did this correctly and is unchanged apart from a stale //advanced comment. Introduced in 906c632d73 (2013, the 1.6.2 schema update), so this has been present for ~13 years.

Reproduced against a build before fixing, full matrix through ParamXMLFile().load:

advanced required tags produced
"true" absent advanced, required spurious
"true" "false" advanced ok (accidentally)
"true" "true" advanced, required ok
absent/"false" "true" required ok
absent/"false" absent/"false" — ok

A load/store round trip persists it. The same fixture gives a clean A/B, identical input through the two branches:

<ITEM     name="adv_true_req_absent" ... required="true"  advanced="true" />   <!-- corrupted -->
<ITEMLIST name="list_adv_true_req_absent" ... required="false" advanced="true"> <!-- correct -->

Scope. Current OpenMS writers do not produce affected files: ParamXMLFile::writeXMLToStream and ParamCTDFile always emit required="true"|"false" explicitly. The faulty branch is reached by hand-written and third-party INI/CTD files, and by OpenMS INIs written against the Param 1.0–1.2 schemas, which defined advanced as an ITEM attribute but had no required attribute at all (Param_1_0.xsd, Param_1_1.xsd, Param_1_2.xsd). required is optional per Param_1_8_0.xsd (default="false"), and the default is not injected on load since parsing does not run schema validation.

Ordinary TOPP execution is unaffected: ParameterInformation::required is built at registration from in-memory defaults (TOPPBase.cpp:953), not from the loaded INI, and no registerFullParam_ call site passes a file-loaded Param. Param::checkDefaults never inspects tags either. The visible effects are the INIFileEditor/ParamEditor required-highlight, ToolsDialog output pre-selection, and src/pyOpenMS/pyTOPP/CTDsupport.py:18, which turns the tag into a mandatory CTDopts argument when an affected loaded Param is used to build the model.

2. XQuestResultXMLHandler, search_hit branch — #9766, found during review

 std::string fdr_type;
-if (this->optionalAttributeAsString_(xprophet_f, attributes, "fdr_type") && !fdr_type.empty())
+if (this->optionalAttributeAsString_(fdr_type, attributes, "fdr_type") && !fdr_type.empty())

Strictly worse: fdr_type was never written, so !fdr_type.empty() was unconditionally false and the body unreachable. XFDR:fdr_type could never be restored from a .xquest.xml, even though XFDRAlgorithm.cpp:221 sets it and the writer emits it at XQuestResultXMLHandler.cpp:1152 — write-only metadata. XFDRAlgorithm_test asserts the value exists, but in memory after the algorithm runs, never through the reader.

Tests

New Param_advanced_no_required.ini covers representative combinations plus an ITEMLIST control, loaded directly rather than produced by the writer. The pre-existing fixtures miss this for two different reasons, which is why a writer round trip alone would not be enough: Param_pre16_update.ini uses tags="advanced" with no advanced attribute at all, and Param_post16_update.ini carries an explicit required="false".

xprophet_f/fdr_type added to one hit in the xquest fixture, asserted after the initial load and after the store/load round trip, with XFDR:used_for_FDR as the control. The hit is located by its OpenPepXL:id rather than by index — load() regroups hits via combineTopRanksFromPairs, so index 0 is deterministic but incidental — and the match count is asserted so the test fails loudly if the fixture stops carrying the attributes.

Both tests were confirmed to fail against the unfixed sources (only the targeted assertions failed; every control passed) and to pass with them. A scan of src/tests, share and src/pyOpenMS found exactly one <ITEM advanced="true"> lacking required in the whole repo — the new fixture — and no tool-input .xquest.xml carrying fdr_type, so no reference outputs change. All 50 Param|XQuest|XFDR|OpenPepXL|TOPPBase tests pass locally.

Not addressed

QcMLFile.cpp:820-825 has the same family of hazard: qp_ is a member whose reset at :942 sits inside if (!(qp_.cvAcc == "MS:1000577" && parent_tag == "setQuality")), so a following <qualityParameter> can inherit value/unitAcc/unitRef/flag for any it omits. Left out because fixing it changes qcML parsing semantics rather than restoring clearly intended behavior — happy to split it off into its own issue.

Review notes

Reviewed with an independent model pass, which corrected two claims now fixed above: the original text said only hand-written/third-party files were affected (it missed the Param 1.0–1.2 schema era), and overstated how directly the CTDsupport path is reached. It also flagged the index-0 coupling in the xquest test, now replaced with an id-anchored lookup. No correctness issue was found in either source fix.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed handling of optional required attributes in parameter configuration files for ITEM entries, preventing incorrect persistence of required="true" during load/save round-trips.
    • Fixed restoration of XFDR metadata when importing XQuest result files, ensuring fdr_type is correctly captured as XFDR:fdr_type.
    • Preserved XFDR:fdr_type and XFDR:used_for_FDR across XQuest result file reloads.
  • Tests
    • Added coverage for missing required scenarios and XFDR metadata preservation (including store/load round-trip).

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

XML metadata parsing fixes

Layer / File(s) Summary
Parameter required-attribute parsing
src/openms/source/FORMAT/HANDLERS/ParamXMLHandler.cpp, src/tests/class_tests/openms/data/Param_advanced_no_required.ini, src/tests/class_tests/openms/source/ParamXMLFile_test.cpp, CHANGELOG
ITEM parsing now uses the dedicated required value, with coverage for omitted, explicit, and round-tripped attributes.
XQuest XFDR metadata restoration
src/openms/source/FORMAT/HANDLERS/XQuestResultXMLHandler.cpp, src/tests/class_tests/openms/data/XQuestResultXMLFile_test_data.xquest.xml, src/tests/class_tests/openms/source/XQuestResultXMLFile_test.cpp
fdr_type is read into the correct variable, and XFDR:fdr_type plus XFDR:used_for_FDR are verified across load/store/load cycles.

Possibly related issues

  • #9766: Directly addresses the same XQuestResultXMLHandler fdr_type parsing bug and its regression coverage.

Poem

A rabbit found two tags astray,
And nudged their parsing back in place.
FDR hopped through XML bright,
Round-trips kept its values right.
No phantom fields remain today!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The XQuestResultXMLHandler fix and related test/data updates are unrelated to linked issue #9763. Split the XQuestResultXMLHandler changes into a separate PR or link the corresponding issue so scope matches the tracked requirement.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The ParamXMLHandler fix and omitted-required regression test satisfy linked issue #9763.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: both optional attributes were parsed into the wrong variable.
📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #9763

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/9763-paramxml-required-attribute

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ariable

Two instances of the same defect: an optionalAttributeAs*_ call whose output
argument is a different variable than the one declared for it. Because
optionalAttributeAsString_ leaves its output untouched when the attribute is
absent, the stale value of a previously parsed attribute is what gets tested.

ParamXMLHandler (ITEM branch)
  'required' was parsed into advanced_string, which was also the variable
  tested, so an <ITEM advanced="true"> that omitted the optional 'required'
  attribute was silently tagged "required". The ITEMLIST branch, added one day
  later in fc5ce40, already did this correctly and is unchanged apart from a
  stale //advanced comment. Introduced in 906c632 (2013, 1.6.2 schema).

  Current OpenMS writers do not produce affected files: ParamXMLFile and
  ParamCTDFile always emit required="true"/"false" explicitly. The faulty branch
  is reached by hand-written and third-party INI/CTD files, and by OpenMS INIs
  written against the Param 1.0-1.2 schemas, which defined 'advanced' but had no
  'required' attribute at all. A load/store round trip persists the spurious
  tag. Ordinary TOPP execution is unaffected because
  ParameterInformation::required comes from registration, not from the loaded
  INI; the visible effects are INIFileEditor/ParamEditor highlighting, and
  pyOpenMS CTDsupport making a parameter mandatory when an affected loaded Param
  is used to build a CTDopts model.

XQuestResultXMLHandler (search_hit branch)
  'fdr_type' was parsed into xprophet_f while the guard tested
  !fdr_type.empty() on a string that was never written, making the guard
  unconditionally false. XFDR:fdr_type could therefore never be read back from
  a .xquest.xml file although XFDRAlgorithm sets it and the writer emits it.

Tests
  New Param_advanced_no_required.ini fixture covers representative
  advanced/required combinations plus an ITEMLIST control, loaded directly
  rather than produced by the writer, which always emits the attribute and so
  cannot expose the bug. The pre-existing fixtures miss it for two different
  reasons: Param_pre16_update.ini uses tags="advanced" with no 'advanced'
  attribute, and Param_post16_update.ini carries an explicit required="false".

  xprophet_f/fdr_type added to one hit in the xquest fixture, asserted after the
  initial load and after the store/load round trip. The hit is located by its
  OpenPepXL:id rather than by index so the assertions do not depend on the
  order in which load() groups hits, and the match count is asserted too.

  Both tests were confirmed to fail against the unfixed sources and pass with
  them. A scan of src/tests, share and src/pyOpenMS found no other data file
  with an <ITEM advanced="true"> lacking 'required', and no tool-input
  .xquest.xml carrying fdr_type, so no reference outputs change.

fixes #9763
fixes #9766

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the fix/9763-paramxml-required-attribute branch from 0a681f0 to d2fbb5c Compare July 20, 2026 14:49
@timosachsenberg
timosachsenberg merged commit 7ee0ccc into develop Jul 20, 2026
39 checks passed
@timosachsenberg
timosachsenberg deleted the fix/9763-paramxml-required-attribute branch July 20, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant