Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed May 18, 2024
1 parent fc478c5 commit 1fd9a49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion singer_sdk/helpers/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def increment_state(
new_rk_value = to_json_compatible(latest_record[replication_key])

if new_rk_value is None:
logger.warning("New replication is null")
logger.warning("New replication value is null")
return

if old_rk_value is None or not check_sorted or new_rk_value >= old_rk_value:
Expand Down
28 changes: 28 additions & 0 deletions tests/core/test_state_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import logging

import pytest

from singer_sdk.helpers import _state
Expand Down Expand Up @@ -127,3 +129,29 @@ def test_irresumable_state():
"replication_key_value": "2021-05-17T20:41:16Z",
},
}


def test_null_replication_value(caplog):
stream_state = {
"replication_key": "updated_at",
"replication_key_value": "2021-05-17T20:41:16Z",
}
latest_record = {"updated_at": None}
replication_key = "updated_at"
is_sorted = True
check_sorted = False

with caplog.at_level(logging.WARNING):
_state.increment_state(
stream_state,
latest_record=latest_record,
replication_key=replication_key,
is_sorted=is_sorted,
check_sorted=check_sorted,
)

assert (
stream_state["replication_key_value"] == "2021-05-17T20:41:16Z"
), "State should not be updated."
assert caplog.records[0].levelname == "WARNING"
assert "is null" in caplog.records[0].message

0 comments on commit 1fd9a49

Please # to comment.