Skip to content

fix: keep XML comments in convertWellSchema.py - #4134

Open
adricortes wants to merge 1 commit into
GEOS-DEV:developfrom
adricortes:bugfix/adricortes/convert-well-schema-keep-comments
Open

fix: keep XML comments in convertWellSchema.py#4134
adricortes wants to merge 1 commit into
GEOS-DEV:developfrom
adricortes:bugfix/adricortes/convert-well-schema-keep-comments

Conversation

@adricortes

Copy link
Copy Markdown

Fixes #4133.

convertWellSchema.py dropped every comment from the deck it converted. The loss was silent — the output validated against the schema, so nothing warned the user.

What this changes

  1. Comments inside the root. The three ET.parse(xml_file) call sites now pass a parser built with insert_comments=True. xml.etree drops comments without it.
  2. The prolog. xml.etree keeps no node before the root element, so a header comment survives neither the parse nor the write. Two new helpers handle it: read_prolog_comments() runs at the start of main1() and add_estimator(), before anything is written; write_prolog_comments() puts the comments back after the conversion succeeds. The order matters, because --replace is the default and the source and the target are then the same file.

Verification

Two corner-point decks with wells, holding 5 and 3 comments, converted both in place and to a separate file.

  • Before: 0 comments in the output.
  • After: every comment is present, in its original position, on its own line.
  • The converted well structure is unchanged: 8 WellControls become 8 wells with their BHP and rate constraints, and no other element differs.
  • Both converted decks pass XSD validation.
  • Both run to completion in GEOS and reproduce the pre-migration results bit for bit, over 101 snapshots and 500 simulated years.

Note

Both helpers return early when lxml is absent, so the script keeps working without it. The prolog is then lost as before, but the in-root comments still survive.

🤖 Generated with Claude Code

The script dropped every comment from the deck it converted. The loss was
silent: the output validated against the schema, so nothing warned the user.

Comments inside the root are lost because xml.etree drops them by default.
The three ET.parse call sites now pass a parser built with
insert_comments=True.

The prolog is a separate loss. xml.etree keeps no node before the root
element, so a header comment survives neither the parse nor the write.
read_prolog_comments() now runs before anything is written, and
write_prolog_comments() puts those comments back afterwards. The order
matters, because --replace is the default and the source and the target
are then the same file.

Both helpers return early when lxml is absent, so the script keeps working
without it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convertWellSchema.py silently drops every XML comment

1 participant