fix: keep XML comments in convertWellSchema.py - #4134
Open
adricortes wants to merge 1 commit into
Open
Conversation
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>
adricortes
requested review from
OmarDuran,
bd713,
joshua-white and
rrsettgast
as code owners
August 31, 2026 16:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4133.
convertWellSchema.pydropped 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
ET.parse(xml_file)call sites now pass a parser built withinsert_comments=True.xml.etreedrops comments without it.xml.etreekeeps 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 ofmain1()andadd_estimator(), before anything is written;write_prolog_comments()puts the comments back after the conversion succeeds. The order matters, because--replaceis 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.
WellControlsbecome 8 wells with their BHP and rate constraints, and no other element differs.Note
Both helpers return early when
lxmlis 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