GEOS-DEV / GEOS-DEV/GEOS

convertWellSchema.py silently drops every XML comment

Open
#4,133 0 comments 0 reactions 0 assignees View on GitHub

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 100
  • removeUseMass() — line 301
  • add_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
  1. Take any deck with <WellControls> and at least one comment.
  2. Run python3 scripts/convertWellSchema.py -s deck.xml -t out.xml --xsd src/coreComponents/schema/schema.xsd.
  3. Compare grep -c '<!--' deck.xml with grep -c '<!--' out.xml.

Observed on two decks: 3 comments to 0, and 5 comments to 0.

Suggested fix
  1. Pass a comment-preserving parser at the three call sites: ET.XMLParser(target=ET.TreeBuilder(insert_comments=True)).
  2. Read the prolog comments with lxml before the conversion writes anything, then put them back afterwards. The read must come first, because --replace is 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.