[ENH] V1 -> V2 Migration - Flows (module)#1609
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1609 +/- ##
==========================================
- Coverage 54.64% 54.53% -0.11%
==========================================
Files 63 63
Lines 5124 5169 +45
==========================================
+ Hits 2800 2819 +19
- Misses 2324 2350 +26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
614411f to
36184e5
Compare
|
Hi @geetu040 !! Can you review the pre-commit failure It was due to merge conflicts more specifically for tasks . Should I change it on my branch ? |
can you try again, sync your branch with mine? It should be fixed now. |
|
I think that due to conflicts it did not synced properly . I have to revert it manually |
geetu040
left a comment
There was a problem hiding this comment.
Nice overall, few changes needed. I'll look at the tests later when the implementation is final.
…into flow-migration-stacked
…into flow-migration-stacked
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
…into flow-migration-stacked
Signed-off-by: Omswastik-11 <omswastikpanda11@gmail.com>
geetu040
left a comment
There was a problem hiding this comment.
sdk code look good so far, please take a look at #1575 (comment) and make changes accordingly where needed.
all tests (existing and new) should pass to make sure we are retaining the original functionality of the sdk
Co-authored-by: Armaghan Shakir <raoarmaghanshakir040@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| @pytest.mark.test_server() | ||
| def test_flow_v1_get(flow_v1): | ||
| flow = flow_v1.get(flow_id=1) | ||
| _validate_flow(flow) |
There was a problem hiding this comment.
Link doesn't work for me, but it seems like _validate_flow is part of this PR.
There was a problem hiding this comment.
2 parallel commits created this confusion but was fixed later.
actually the function was defined as _assert_flow_shape but used as _validate_flow, copilot suggested to fix the name where it was used, we rather changed the name of the function where it was defined.
Co-authored-by: Armaghan Shakir <raoarmaghanshakir040@gmail.com>
Co-authored-by: Armaghan Shakir <raoarmaghanshakir040@gmail.com>
geetu040
left a comment
There was a problem hiding this comment.
Nice work @Omswastik-11.
@PGijsbers please review/merge.
PGijsbers
left a comment
There was a problem hiding this comment.
Thanks! Minor comment with a question to take into consideration going forward.
| @staticmethod | ||
| def _convert_v2_to_v1_format(v2_json: dict[str, Any]) -> dict[str, Any]: | ||
| """Convert v2 JSON response to v1 XML-dict format for OpenMLFlow._from_dict(). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| v2_json : dict | ||
| The v2 JSON response from the server. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict | ||
| A dictionary matching the v1 XML structure expected by OpenMLFlow._from_dict(). | ||
| """ | ||
| # Map v2 JSON fields to v1 XML structure with oml: namespace | ||
| flow_dict = { | ||
| "oml:flow": { | ||
| "@xmlns:oml": "http://openml.org/openml", | ||
| "oml:id": str(v2_json.get("id", "0")), | ||
| "oml:uploader": str(v2_json.get("uploader", "")), | ||
| "oml:name": v2_json.get("name", ""), | ||
| "oml:version": str(v2_json.get("version", "")), | ||
| "oml:external_version": v2_json.get("external_version", ""), | ||
| "oml:description": v2_json.get("description", ""), | ||
| "oml:upload_date": ( | ||
| v2_json.get("upload_date", "").replace("T", " ") | ||
| if v2_json.get("upload_date") | ||
| else "" | ||
| ), | ||
| "oml:language": v2_json.get("language", ""), | ||
| "oml:dependencies": v2_json.get("dependencies", ""), | ||
| } | ||
| } | ||
|
|
||
| # Add optional fields | ||
| if "class_name" in v2_json: | ||
| flow_dict["oml:flow"]["oml:class_name"] = v2_json["class_name"] | ||
| if "custom_name" in v2_json: | ||
| flow_dict["oml:flow"]["oml:custom_name"] = v2_json["custom_name"] | ||
|
|
||
| # Convert parameters from v2 array to v1 format | ||
| if v2_json.get("parameter"): | ||
| flow_dict["oml:flow"]["oml:parameter"] = [ | ||
| { | ||
| "oml:name": param.get("name", ""), | ||
| "oml:data_type": param.get("data_type", ""), | ||
| "oml:default_value": str(param.get("default_value", "")), | ||
| "oml:description": param.get("description", ""), | ||
| } | ||
| for param in v2_json["parameter"] | ||
| ] | ||
|
|
||
| # Convert subflows from v2 to v1 components format | ||
| if v2_json.get("subflows"): | ||
| flow_dict["oml:flow"]["oml:component"] = [ | ||
| { | ||
| "oml:identifier": subflow.get("identifier", ""), | ||
| "oml:flow": FlowV2API._convert_v2_to_v1_format(subflow["flow"])["oml:flow"], | ||
| } | ||
| for subflow in v2_json["subflows"] | ||
| ] | ||
|
|
||
| # Convert tags from v2 array to v1 format | ||
| if v2_json.get("tag"): | ||
| flow_dict["oml:flow"]["oml:tag"] = v2_json["tag"] | ||
|
|
||
| return flow_dict |
There was a problem hiding this comment.
I might be missing something, but it seems to me like just having a separate parser would have been more useful. Or even allowing the parser to be called with or without a required oml: prefix. Largely because after sunset of v1, we wouldn't want to keep this code around anymore, so we would have to do extra work.
Considering it works now and this is easily addressed as a separate PR at a later date, I'm not going to request a change here. If there were considerations or attempts that prevented you from doing it that way, I would be interested to hear about them so they can be taken into account when this is worked on in the future.
There was a problem hiding this comment.
I don't think anything prevented from doing it that way. Btw in a long-term plan, are you suggesting to update the schema definition of flow dict?
Also I don't think I exactly get your idea of separate parser. Are you thinking of a general json to xml parser that could work across several other cases in code?
| @pytest.mark.test_server() | ||
| def test_flow_v1_get(flow_v1): | ||
| flow = flow_v1.get(flow_id=1) | ||
| _validate_flow(flow) |
There was a problem hiding this comment.
Link doesn't work for me, but it seems like _validate_flow is part of this PR.
Fixes #1601
added a
Createmethod inFlowAPIfor publishing flow but not refactored with oldpublish. (Needs discussion on this)Added tests using
fake_methodsso that we can test without localV2server . I have tested theFlowsV2methods (getandexists) anddeleteandlistwere not implemented inV2server so I skipped them .