Skip to content

fix: crash/leak fixes in reader, source, writer and CLI arg parsing - #73

Open
maan-iitd2 wants to merge 1 commit into
blackrock:mainfrom
maan-iitd2:pr/ingen-library-fixes
Open

fix: crash/leak fixes in reader, source, writer and CLI arg parsing#73
maan-iitd2 wants to merge 1 commit into
blackrock:mainfrom
maan-iitd2:pr/ingen-library-fixes

Conversation

@maan-iitd2

Copy link
Copy Markdown

What

Five small, independent crash/leak fixes in existing ingen library code. No behavior change for any config that was already working — each fix only changes what happens on a previously-unhandled error path.

File Before After
ingen/reader/xml_file_reader.py Parsed the XML file twice (xmltodict + a second ElementTree.parse) and never closed the file handle if parsing raised Single read via xmltodict, file handle closed via with, parent tag derived from the parsed dict (also fixes a namespace-prefix mismatch between the two parsers)
ingen/data_source/json_source.py json_dict[self.id] raised a raw KeyError if the id was absent from the payload Raises the documented ValueError("JSON source with ID {} does not exist")
ingen/writer/util.py Unknown header/footer prop type failed with TypeError: 'NoneType' object is not callable; get_new_line(False) returned None, which breaks the custom_string + result concatenation in get_custom_value Unknown type raises a clear ValueError; get_new_line returns '' for the false case
ingen/pre_processor/outer_join.py Missing/unmatched source in config surfaced as AttributeError: 'NoneType' object has no attribute 'columns' Raises a clear KeyError naming the problem
ingen/utils/utils.py (KeyValue CLI action) value.split('=') on --query_params/--override_params broke for any value containing its own = (tokens, URLs with query strings, col=val fragments) Splits on the first = only, matching KeyValueOrString's existing behaviour

Why these and not others

This PR intentionally excludes two other fixes from the same working branch (not_equals_filter.py raising on a missing source, and a replace_in_list NaN-matching change) because those alter existing behavior rather than just fixing a crash. Happy to open those separately with more discussion if maintainers want them.

Testing

  • Added a regression test per fix (9 files touched, 5 source + 4 test — outer_join's test already existed and got 2 new cases).
  • Full suite: pytest test/ — 399 passed / 33 failed, identical failure set and count on unmodified main (confirmed by running the suite before and after this diff). The 33 failures are pre-existing environment issues (missing GPG binary, Windows file locks, live network calls) unrelated to this change.
  • End-to-end: ran python -m ingen against a real config with an XML source and --query_params containing an embedded =, and manually exercised get_custom_value, get_new_line, OuterJoin.execute, and JsonSource.fetch against real (non-mocked) objects to confirm each fix behaves as described.
  • git diff --ignore-all-space main confirms these are the only 5 real line changes — no line-ending noise.

🤖 Generated with Claude Code

- xml_file_reader: stop double-parsing the file (xmltodict + a second
  ElementTree pass) and leaking the file handle on exceptions; derive
  the parent tag from the already-parsed dict instead.
- json_source: raise the documented ValueError when the configured id
  key is absent from the payload, instead of an unguarded KeyError.
- writer/util: raise a clear ValueError for an unknown header/footer
  prop type instead of a bare "NoneType not callable"; make
  get_new_line return '' (not None) when the flag is false, so string
  concatenation in get_custom_value doesn't blow up.
- outer_join: raise a clear KeyError when the config omits 'source' or
  names a source that was never fetched, instead of an AttributeError
  deep in pandas.
- utils.KeyValue: split CLI key=value args on the first '=' only, so
  values containing '=' (tokens, URLs, SQL fragments) survive.

Each fix ships with a regression test; none change output for
already-valid configs. Verified against the full test suite (no
regressions vs main) and an end-to-end `python -m ingen` run.

Signed-off-by: maan-iitd2 <maan.iitd.ac.in@gmail.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.

2 participants