Skip to content

Commit 7b971b4

Browse files
authored
Some of the fields in "partial rerun merge" events should be optional
2 parents ddeeac1 + 416babf commit 7b971b4

File tree

6 files changed

+75
-22
lines changed

6 files changed

+75
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Most of the fields in partial merge events should be optional.
11+
912

1013
## [1.11.1] - 2023-12-18
1114

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ omit =
2727
docs/modules/ROOT/examples/logging/tutorial005.py
2828
docs/modules/ROOT/examples/followable/tutorial001.py
2929
src/corva/__init__.py
30+
src/version.py
3031

3132
[isort]
3233
profile = black

src/corva/handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ def _merge_events(
576576
Only "scheduled" and "stream" type of apps can be processed here.
577577
If somehow any other type is passed - raise an exception
578578
"""
579+
if not isinstance(
580+
aws_event, list
581+
): # if aws_event is not a list - there is nothing to merge, so do nothing.
582+
return aws_event
583+
579584
if data_transformation_type is RawScheduledEvent:
580585
# scheduled event
581586
if not isinstance(aws_event[0], dict):

src/corva/models/merge/merge.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from corva.models.base import CorvaBaseEvent
24
from corva.models.merge.enums import EventType, RerunMode, SourceType
35

@@ -25,23 +27,23 @@ class PartialRerunMergeEvent(CorvaBaseEvent):
2527
run_until: run until
2628
"""
2729

28-
event_type: EventType
29-
partial_well_rerun_id: int
30-
rerun_mode: RerunMode
31-
start: int
32-
end: int
30+
event_type: Optional[EventType]
31+
partial_well_rerun_id: Optional[int]
32+
rerun_mode: Optional[RerunMode]
33+
start: Optional[int]
34+
end: Optional[int]
3335
asset_id: int
3436
rerun_asset_id: int
3537
app_stream_id: int
3638
rerun_app_stream_id: int
37-
version: int
38-
app_id: int
39-
app_key: str
39+
version: Optional[int]
40+
app_id: Optional[int]
41+
app_key: Optional[str]
4042
app_connection_id: int
4143
rerun_app_connection_id: int
42-
source_type: SourceType
43-
log_type: str
44-
run_until: int
44+
source_type: Optional[SourceType]
45+
log_type: Optional[str]
46+
run_until: Optional[int]
4547

4648
class Config:
4749
extra = "allow"

src/corva/models/merge/raw.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, Dict, List
3+
from typing import Any, Dict, List, Optional
44

55
import pydantic
66

@@ -9,24 +9,24 @@
99

1010

1111
class RawPartialMergeEventData(pydantic.BaseModel):
12-
partial_well_rerun_id: int
13-
rerun_mode: RerunMode
14-
start: int
15-
end: int
12+
partial_well_rerun_id: Optional[int]
13+
rerun_mode: Optional[RerunMode]
14+
start: Optional[int]
15+
end: Optional[int]
1616
asset_id: int
1717
rerun_asset_id: int
1818
app_stream_id: int
1919
rerun_app_stream_id: int
2020
version: int = pydantic.Field(
2121
..., le=1, ge=1
2222
) # Currently handler supports only 1-st version of this event.
23-
app_id: int
24-
app_key: str
23+
app_id: Optional[int]
24+
app_key: Optional[str]
2525
app_connection_id: int
2626
rerun_app_connection_id: int
27-
source_type: SourceType
28-
log_type: str
29-
run_until: int
27+
source_type: Optional[SourceType]
28+
log_type: Optional[str]
29+
run_until: Optional[int]
3030

3131
class Config:
3232
extra = "allow"

tests/unit/test_partial_rerun_merge_app.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Module contains functional requirements for partial rerun merge event handler."""
2-
2+
from copy import deepcopy
33
from uuid import uuid4
44

55
import pytest
@@ -121,3 +121,45 @@ def partial_rerun_merge_app(event, api, asset_cache, rerun_asset_cache):
121121

122122
partial_merge_app_response = scheduled_app(RAW_EVENT, context)[0]
123123
assert partial_merge_app_response == expected_response
124+
125+
126+
def test_event_parsing_not_failing_on_missing_field(context):
127+
"""
128+
When field is missing we're still able to parse the event and invoke correct
129+
function
130+
"""
131+
132+
@corva.scheduled(merge_events=True)
133+
def scheduled_app(event, api, cache):
134+
pytest.fail("Scheduled app was unexpectedly called!")
135+
136+
@corva.partial_rerun_merge
137+
def partial_rerun_merge_app(event, api, asset_cache, rerun_asset_cache):
138+
return True
139+
140+
event_with_missing_parameter: dict = deepcopy(RAW_EVENT)
141+
event_with_missing_parameter["data"]["end"] = None
142+
partial_merge_app_response = scheduled_app(event_with_missing_parameter, context)[0]
143+
assert partial_merge_app_response is True
144+
145+
146+
def test_merge_events_does_not_fail_for_partial_rerun_merge_events(context, mocker):
147+
"""
148+
partial rerun merge events shouldn't fail to be processed when used in combination
149+
with merge_events parameter
150+
"""
151+
152+
@corva.scheduled(merge_events=True)
153+
def scheduled_app(event, api, cache):
154+
pytest.fail("Scheduled app was unexpectedly called!")
155+
156+
@corva.partial_rerun_merge
157+
def partial_rerun_merge_app(event, api, asset_cache, rerun_asset_cache):
158+
return True
159+
160+
partial_merge_app_response = scheduled_app(RAW_EVENT, context)[0]
161+
assert partial_merge_app_response is True
162+
163+
164+
def test_partial_rerun_decorator_can_be_called_directly(context):
165+
corva.partial_rerun_merge()

0 commit comments

Comments
 (0)