Skip to content

convertWellSchema.py silently drops every XML comment #4133

Description

@adricortes

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 24a8410, Python 3.11, lxml 6.1.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions