3535 JsonPlusSerializer ,
3636 _msgpack_enc ,
3737 _msgpack_ext_hook_to_json ,
38+ _warned_blocked_types ,
39+ _warned_unregistered_types ,
3840)
3941from langgraph .store .base import Item
4042
@@ -580,6 +582,14 @@ def test_msgpack_safe_types_no_warning(caplog: pytest.LogCaptureFixture) -> None
580582 assert result is not None
581583
582584
585+ @pytest .fixture (autouse = True )
586+ def _reset_warned_types () -> None :
587+ # Warning dedup state is process-global; reset per-test so each case sees
588+ # a fresh slate and assertions about warning emission are stable.
589+ _warned_unregistered_types .clear ()
590+ _warned_blocked_types .clear ()
591+
592+
583593def test_msgpack_pydantic_warns_by_default (caplog : pytest .LogCaptureFixture ) -> None :
584594 """Pydantic models not in allowlist should log warning but still deserialize."""
585595 current = _lg_msgpack .STRICT_MSGPACK_ENABLED
@@ -595,6 +605,12 @@ def test_msgpack_pydantic_warns_by_default(caplog: pytest.LogCaptureFixture) ->
595605 assert "unregistered type" in caplog .text .lower ()
596606 assert "allowed_msgpack_modules" in caplog .text
597607 assert result == obj
608+
609+ # Second deserialization of the same type should NOT produce another warning
610+ caplog .clear ()
611+ result2 = serde .loads_typed (dumped )
612+ assert "unregistered type" not in caplog .text .lower ()
613+ assert result2 == obj
598614 _lg_msgpack .STRICT_MSGPACK_ENABLED = current
599615
600616
@@ -639,7 +655,6 @@ def test_msgpack_allowlist_silences_warning(caplog: pytest.LogCaptureFixture) ->
639655
640656def test_msgpack_none_blocks_unregistered (caplog : pytest .LogCaptureFixture ) -> None :
641657 """allowed_msgpack_modules=None should block unregistered types."""
642-
643658 serde = JsonPlusSerializer (allowed_msgpack_modules = None )
644659
645660 obj = MyPydantic (foo = "test" , bar = 42 , inner = InnerPydantic (hello = "world" ))
@@ -657,7 +672,6 @@ def test_msgpack_allowlist_blocks_non_listed(
657672 caplog : pytest .LogCaptureFixture ,
658673) -> None :
659674 """Allowlists should block unregistered types even if msgpack is enabled."""
660-
661675 serde = JsonPlusSerializer (
662676 allowed_msgpack_modules = [("tests.test_jsonplus" , "MyPydantic" )]
663677 )
0 commit comments