Skip to content

Commit 4291306

Browse files
fix: return instance instead of incrementing match in Workflow validation
1 parent d70535c commit 4291306

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

.generation/post-process/python.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def file_modifications() -> Generator[tuple[Path, FileModifier], None, None]:
2626
yield Path("models/task_status_with_id.py"), task_status_with_id_py
2727
yield Path("models/time_step.py"), time_step_py
2828
yield Path("models/vector_result_descriptor.py"), vector_result_descriptor_py
29+
yield Path("models/workflow.py"), workflow_py
2930

3031

3132
def main():
@@ -37,6 +38,17 @@ def main():
3738
)
3839

3940

41+
def workflow_py(file_contents: list[str]) -> Generator[str, None, None]:
42+
"""Modify the workflow.py file."""
43+
for line in file_contents:
44+
dedented_line = dedent(line)
45+
46+
if dedented_line.startswith("match += 1"):
47+
line = indent("return instance", 3 * INDENT) + "\n"
48+
49+
yield line
50+
51+
4052
def api_client_py(file_contents: list[str]) -> Generator[str, None, None]:
4153
"""Modify the api_client.py file."""
4254
for line in file_contents:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--- python/geoengine_openapi_client/models/workflow.py
2+
+++ python/geoengine_openapi_client/models/workflow.py
3+
@@ -62,12 +62,12 @@
4+
if not isinstance(v, TypedOperator):
5+
error_messages.append(f"Error! Input type `{type(v)}` is not `TypedOperator`")
6+
else:
7+
- match += 1
8+
+ return instance
9+
# validate data type: LegacyTypedOperator
10+
if not isinstance(v, LegacyTypedOperator):
11+
error_messages.append(f"Error! Input type `{type(v)}` is not `LegacyTypedOperator`")
12+
else:
13+
- match += 1
14+
+ return instance
15+
if match > 1:
16+
# more than 1 match
17+
raise ValueError("Multiple matches found when setting `actual_instance` in Workflow with oneOf schemas: LegacyTypedOperator, TypedOperator. Details: " + ", ".join(error_messages))
18+
@@ -91,13 +91,13 @@
19+
# deserialize data into TypedOperator
20+
try:
21+
instance.actual_instance = TypedOperator.from_json(json_str)
22+
- match += 1
23+
+ return instance
24+
except (ValidationError, ValueError) as e:
25+
error_messages.append(str(e))
26+
# deserialize data into LegacyTypedOperator
27+
try:
28+
instance.actual_instance = LegacyTypedOperator.from_json(json_str)
29+
- match += 1
30+
+ return instance
31+
except (ValidationError, ValueError) as e:
32+
error_messages.append(str(e))
33+

python/geoengine_openapi_client/models/workflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ def actual_instance_must_validate_oneof(cls, v):
6262
if not isinstance(v, TypedOperator):
6363
error_messages.append(f"Error! Input type `{type(v)}` is not `TypedOperator`")
6464
else:
65-
match += 1
65+
return instance
6666
# validate data type: LegacyTypedOperator
6767
if not isinstance(v, LegacyTypedOperator):
6868
error_messages.append(f"Error! Input type `{type(v)}` is not `LegacyTypedOperator`")
6969
else:
70-
match += 1
70+
return instance
7171
if match > 1:
7272
# more than 1 match
7373
raise ValueError("Multiple matches found when setting `actual_instance` in Workflow with oneOf schemas: LegacyTypedOperator, TypedOperator. Details: " + ", ".join(error_messages))
@@ -91,13 +91,13 @@ def from_json(cls, json_str: str) -> Self:
9191
# deserialize data into TypedOperator
9292
try:
9393
instance.actual_instance = TypedOperator.from_json(json_str)
94-
match += 1
94+
return instance
9595
except (ValidationError, ValueError) as e:
9696
error_messages.append(str(e))
9797
# deserialize data into LegacyTypedOperator
9898
try:
9999
instance.actual_instance = LegacyTypedOperator.from_json(json_str)
100-
match += 1
100+
return instance
101101
except (ValidationError, ValueError) as e:
102102
error_messages.append(str(e))
103103

0 commit comments

Comments
 (0)