Skip to content

984: define subversion workaround#1697

Merged
SFJohnson24 merged 8 commits into
mainfrom
984-define-version-reporting
Apr 30, 2026
Merged

984: define subversion workaround#1697
SFJohnson24 merged 8 commits into
mainfrom
984-define-version-reporting

Conversation

@alexfurmenkov
Copy link
Copy Markdown
Collaborator

changing 2.1.* subversions to 2.1 in define.xml before creating odm reader.

original version stored in DefineXmlReader, accessed in get_define_version to be shown in report

@alexfurmenkov alexfurmenkov linked an issue Apr 22, 2026 that may be closed by this pull request
@alexfurmenkov alexfurmenkov changed the title define subversion workaround 984: define subversion workaround Apr 22, 2026
original_version = match.group(2)
xml_content = re.sub(define_version_pattern, r"\g<1>2.1\3", xml_content)

with tempfile.NamedTemporaryFile(mode="w+", suffix=".xml", delete=False) as tmp:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep delete = True so temp files are cleaned up after done use

return reader

@classmethod
def from_file_contents(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalization is only added to from filename but from_file_contents is missing it.


@classmethod
def from_filename(cls, filename: str):
"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please restore the docstring on this function?

DefineXMLReader20,
DefineXMLReader21,
)
_DEFINE_VERSION_RE = re.compile(r'(?<=def:DefineVersion=")2\.1\.\d+(?=")')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex is too brittle for a define xml. The rest of the factory uses ElementTree to inspect actual attribute Namespaces. Do you think that would be a better approach?

reader: BaseDefineXMLReader = define_xml_reader_class(
cache_service_obj, study_id, data_bundle_id
if isinstance(file_contents, bytes):
file_contents: str = file_contents.decode("utf-8")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing to 'UTF-8' can introduce regression here. ElementTree.Fromstring handles the encodings better. If you are sure that Define-XML will always be 'UTF-8' please let me know and then you can ignore this comment.

# Conflicts:
#	cdisc_rules_engine/services/define_xml/define_xml_reader_factory.py
ElementTree.parse(filename).getroot()
)
reader: BaseDefineXMLReader = define_xml_reader_class()
reader._odm_loader.open_odm_document(filename)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change here changes the behavior of from_filename to read using a string instead of odm_loader and also will hardcode the define xml encoding to UTF-8. @gerrycampion please let us know if you agree with this change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to read bytes instead, so it will treat xml encoding with respect

Copy link
Copy Markdown
Collaborator

@SFJohnson24 SFJohnson24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR correctly provides work around for define subversions. Passes high level review. Tested with correct validation execution and reporting for v2.0, 2.0.0, 2.1.11, 2.1.0 define

@SFJohnson24 SFJohnson24 merged commit d5bcca9 into main Apr 30, 2026
12 checks passed
@SFJohnson24 SFJohnson24 deleted the 984-define-version-reporting branch April 30, 2026 19:49
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.

Define Version reporting

3 participants