convertWellSchema.py silently drops every XML comment
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 287
- Forks
- 109
- Avg merge
- 4d 41m
- Merged PRs (30d)
- 5
Description
Description
scripts/convertWellSchema.py removes every comment from the deck it converts. The loss is silent: the script reports XSD validation passed and the output is valid, so nothing signals that anything was lost.
GEOS decks use comments to record why a value was chosen — a solver tolerance, a rate derivation, the identity of a saturation table. None of that is recoverable from the output.
Root cause
The script reads the deck with xml.etree.ElementTree, which discards comments by default. Three call sites are affected:
update_constraint_element()— line 100removeUseMass()— line 301add_we()— line 323
All three call tree = ET.parse(xml_file).
A second, separate loss affects the prolog. xml.etree keeps no node before the root element, so a header comment before <Problem> is dropped even after the parser is fixed.
Steps to reproduce
- Take any deck with
<WellControls>and at least one comment. - Run
python3 scripts/convertWellSchema.py -s deck.xml -t out.xml --xsd src/coreComponents/schema/schema.xsd. - Compare
grep -c '<!--' deck.xmlwithgrep -c '<!--' out.xml.
Observed on two decks: 3 comments to 0, and 5 comments to 0.
Suggested fix
- Pass a comment-preserving parser at the three call sites:
ET.XMLParser(target=ET.TreeBuilder(insert_comments=True)). - Read the prolog comments with
lxmlbefore the conversion writes anything, then put them back afterwards. The read must come first, because--replaceis the default and the source and the target are then the same file.
A PR follows.
Environment
GEOS develop at 24a8410b51, Python 3.11, lxml 6.1.2.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in scripts/convertWellSchema.py at update_constraint_element(), removeUseMass(), and add_we(), then reproduce the loss with the supplied command and comment counts. Review how the three ET.parse call sites handle comments and how the prolog is read before --replace writes the target. Done means inline and pre-root comments survive conversion and validation still passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100