Skip to content

fix: keep InstalledPackagesFeatureGroup's output shape on the error path - #1213

Open
dchaudhari7177 wants to merge 1 commit into
mloda-ai:mainfrom
dchaudhari7177:fix/installed-packages-error-shape
Open

fix: keep InstalledPackagesFeatureGroup's output shape on the error path#1213
dchaudhari7177 wants to merge 1 commit into
mloda-ai:mainfrom
dchaudhari7177:fix/installed-packages-error-shape

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Closes #1206

calculate_feature returned {cls.get_class_name(): [packages]} on success but {"error": error_message} on CalledProcessError — a different key, and a bare string where the success path returns a list. The class's own Output Format docstring promises a single column named InstalledPackagesFeatureGroup.

The consequence is the wrong way round: a caller gets a KeyError or a malformed frame precisely when pip freeze has failed and it needs to read the error message. The failure path was the one making failures hard to diagnose.

Now {cls.get_class_name(): [error_message]} — same key, same list-of-one shape, on both paths.

I also corrected the docstring's Implementation Details bullet, which said "On error, returns error message dictionary". That line described the old behaviour and would have contradicted the code after this change.

Test

The failure branch had no coverage at all. The new test patches subprocess.run to raise CalledProcessError and asserts:

assert set(result) == {column}, "the failure path must not introduce another key"

set(result) == {column} rather than column in result on purpose — an in check would still pass if a stray "error" key came back alongside the right one, which is exactly the regression worth catching.

Verified it fails against the old code:

FAILED ...::test_installed_packages_feature_group_error_path_keeps_the_output_shape
1 failed, 2 deselected

With the fix: 3 passed. ruff format / ruff check clean.

mypy --strict on the changed file reports 6 errors in 4 other files (missing pandas stubs in my local env) — byte-identical output on upstream/main with my changes stashed, so nothing new from this PR.

calculate_feature returned {ClassName: [packages]} on success but
{"error": message} on CalledProcessError -- a different key, and a bare string
where the success path returns a list. The class docstring's Output Format
section promises the single ClassName column.

The consequence runs the wrong way: a caller hits a KeyError or a malformed
frame exactly when pip freeze has failed and it is trying to read why. The
error path was the thing making errors hard to diagnose.

Both paths now return {ClassName: [message]}.

The Implementation Details bullet ("On error, returns error message
dictionary") described the old behaviour and would have contradicted the code,
so it is updated with it.

The failure branch had no coverage. The new test patches subprocess.run to
raise and asserts set(result) == {column} rather than `column in result`: an
`in` check still passes if a stray "error" key comes back alongside the right
one, which is the regression worth catching.

Confirmed the test fails against the old return, and passes with the fix.

Closes mloda-ai#1206
@TomKaltofen

Copy link
Copy Markdown
Contributor

@dchaudhari7177 Please address the security findings in the CI.

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.

[Need support]: Fix InstalledPackagesFeatureGroup's error-path return shape

2 participants