Skip to content

Commit 52ce3de

Browse files
Source Marketo: handle null cursor values (#22203)
* #1407 source Marketo: handle null cursor values * #1407 source marketo: upd changelog * auto-bump connector version --------- Co-authored-by: Octavia Squidington III <[email protected]>
1 parent 3dd42d7 commit 52ce3de

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@
10231023
- name: Marketo
10241024
sourceDefinitionId: 9e0556f4-69df-4522-a3fb-03264d36b348
10251025
dockerRepository: airbyte/source-marketo
1026-
dockerImageTag: 1.0.1
1026+
dockerImageTag: 1.0.2
10271027
documentationUrl: https://docs.airbyte.com/integrations/sources/marketo
10281028
icon: marketo.svg
10291029
sourceType: api

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8141,7 +8141,7 @@
81418141
supportsNormalization: false
81428142
supportsDBT: false
81438143
supported_destination_sync_modes: []
8144-
- dockerImage: "airbyte/source-marketo:1.0.1"
8144+
- dockerImage: "airbyte/source-marketo:1.0.2"
81458145
spec:
81468146
documentationUrl: "https://docs.airbyte.com/integrations/sources/marketo"
81478147
connectionSpecification:

airbyte-integrations/connectors/source-marketo/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ COPY source_marketo ./source_marketo
3434
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
3535
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
3636

37-
LABEL io.airbyte.version=1.0.1
37+
LABEL io.airbyte.version=1.0.2
3838
LABEL io.airbyte.name=airbyte/source-marketo

airbyte-integrations/connectors/source-marketo/source_marketo/source.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ def state(self, value):
100100
self._state = value
101101

102102
def get_updated_state(self, current_stream_state: MutableMapping[str, Any], latest_record: Mapping[str, Any]) -> Mapping[str, Any]:
103-
self._state = {
104-
self.cursor_field: max(
105-
latest_record.get(self.cursor_field, self.start_date), current_stream_state.get(self.cursor_field, self.start_date)
106-
)
107-
}
103+
latest_cursor_value = latest_record.get(self.cursor_field, self.start_date) or self.start_date
104+
current_cursor_value = current_stream_state.get(self.cursor_field, self.start_date) or self.start_date
105+
self._state = {self.cursor_field: max(latest_cursor_value, current_cursor_value)}
108106
return self._state
109107

110108
def stream_slices(self, sync_mode, stream_state: Mapping[str, Any] = None, **kwargs) -> Iterable[Optional[MutableMapping[str, any]]]:

airbyte-integrations/connectors/source-marketo/unit_tests/test_source.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
from functools import partial
99
from unittest.mock import ANY, Mock, patch
1010

11+
import pendulum
1112
import pytest
1213
from airbyte_cdk.models.airbyte_protocol import SyncMode
13-
from source_marketo.source import Activities, Campaigns, MarketoStream, Programs, SourceMarketo
14+
from source_marketo.source import Activities, Campaigns, Leads, MarketoStream, Programs, SourceMarketo
1415

1516

1617
def test_create_export_job(mocker, send_email_stream, caplog):
@@ -286,3 +287,30 @@ def test_check_connection(config, requests_mock, status_code, response, is_conne
286287
def test_normalize_datetime(config, input, format, expected_result):
287288
stream = Programs(config)
288289
assert stream.normalize_datetime(input, format) == expected_result
290+
291+
292+
today = pendulum.now()
293+
yesterday = pendulum.now().subtract(days=1).strftime("%Y-%m-%dT%H:%M:%SZ")
294+
today = today.strftime("%Y-%m-%dT%H:%M:%SZ")
295+
296+
297+
@pytest.mark.parametrize(
298+
"latest_record, current_state, expected_state",
299+
(
300+
({}, {}, "start_date"),
301+
({"updatedAt": None}, {"updatedAt": None}, "start_date"),
302+
({}, {"updatedAt": None}, "start_date"),
303+
({"updatedAt": None}, {}, "start_date"),
304+
({}, {"updatedAt": today}, {"updatedAt": today}),
305+
({"updatedAt": None}, {"updatedAt": today}, {"updatedAt": today}),
306+
({"updatedAt": today}, {"updatedAt": None}, {"updatedAt": today}),
307+
({"updatedAt": today}, {}, {"updatedAt": today}),
308+
({"updatedAt": yesterday}, {"updatedAt": today}, {"updatedAt": today}),
309+
({"updatedAt": today}, {"updatedAt": yesterday}, {"updatedAt": today})
310+
)
311+
)
312+
def test_get_updated_state(config, latest_record, current_state, expected_state):
313+
stream = Leads(config)
314+
if expected_state == "start_date":
315+
expected_state = {"updatedAt": config["start_date"]}
316+
assert stream.get_updated_state(latest_record, current_state) == expected_state

docs/integrations/sources/marketo.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ If the 50,000 limit is too stringent, contact Marketo support for a quota increa
106106

107107
| Version | Date | Pull Request | Subject |
108108
|:---------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------|
109-
| `1.0.1` | 2023-01-31 | [22015](https://github.com/airbytehq/airbyte/pull/22015) | Set `AvailabilityStrategy` for streams explicitly to `None` |
109+
| `1.0.2` | 2023-02-01 | [22203](https://github.com/airbytehq/airbyte/pull/22203) | Handle Null cursor values |
110+
| `1.0.1` | 2023-01-31 | [22015](https://github.com/airbytehq/airbyte/pull/22015) | Set `AvailabilityStrategy` for streams explicitly to `None` |
110111
| `1.0.0` | 2023-01-25 | [21790](https://github.com/airbytehq/airbyte/pull/21790) | Fix `activities_*` stream schemas |
111112
| `0.1.12` | 2023-01-19 | [20973](https://github.com/airbytehq/airbyte/pull/20973) | Fix encoding error (note: this change is not in version 1.0.0, but is in later versions |
112113
| `0.1.11` | 2022-09-30 | [17445](https://github.com/airbytehq/airbyte/pull/17445) | Do not use temporary files for memory optimization |

0 commit comments

Comments
 (0)