Skip to content

Conversation

@Omswastik-11
Copy link

@Omswastik-11 Omswastik-11 commented Jan 4, 2026

Summary

This PR refactors run_flow_on_task, which had grown to ~160 lines with high cyclomatic complexity, by extracting small helper functions with clear, single responsibilities. The main function is now a readable orchestrator with clearly defined steps.


Changes

Extracted helper functions

  • _validate_flow_and_task_inputs
    Handles input validation and backward-compatible argument handling

  • _sync_flow_with_server
    Synchronizes the flow with the server and checks for duplicate runs

  • _prepare_run_environment
    Prepares environment information and run tags

  • _create_run_from_results
    Builds the OpenMLRun object from execution results

Internal structure improvements

  • Introduced a _RunResults NamedTuple to bundle execution outputs
    (data_content, trace, evaluations) and reduce long parameter lists

Type Safety Improvements

  • Replaced assert statements with explicit ValueError / TypeError exceptions
  • Added type guards before accessing attributes that may be None
  • Made boolean parameters keyword-only where appropriate

Fixes #1580

@Omswastik-11 Omswastik-11 marked this pull request as ready for review January 5, 2026 14:14
@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 10.16949% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.62%. Comparing base (c5f68bf) to head (6771fb4).

Files with missing lines Patch % Lines
openml/runs/functions.py 10.16% 53 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1596      +/-   ##
==========================================
- Coverage   53.02%   52.62%   -0.41%     
==========================================
  Files          36       36              
  Lines        4326     4342      +16     
==========================================
- Hits         2294     2285       -9     
- Misses       2032     2057      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@geetu040 geetu040 left a comment

Choose a reason for hiding this comment

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

Looks really nice, I have left a few comments with only minor changes requested.

@Omswastik-11 Omswastik-11 requested a review from geetu040 January 13, 2026 09:23
@Omswastik-11
Copy link
Author

added cast(int , task_id) because of mypy pre-commit error .

image

Copy link
Contributor

@geetu040 geetu040 left a comment

Choose a reason for hiding this comment

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

Nicely refactored, LGTM.

CC: @fkiraly, @SimonBlanke for review/merge.

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.

[MNT] Refactor run_flow_on_task-function

4 participants