Skip to content

Commit 5408215

Browse files
committed
Reject JSON-tagged null payloads before no-payload shortcuts
1 parent 1722b7f commit 5408215

16 files changed

Lines changed: 215 additions & 34 deletions

‎CHANGELOG.md‎

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

77
## [Unreleased]
88

9-
The Python SDK advances to prerelease `2.0.0-rc.30`. PyPI displays the normalized
10-
PEP 440 identity `2.0.0rc30`. This Avro-only SDK release is qualified with Server
9+
The Python SDK advances to prerelease `2.0.0-rc.31`. PyPI displays the normalized
10+
PEP 440 identity `2.0.0rc31`. This Avro-only SDK release is qualified with Server
1111
`2.0.0-rc.32`; JSON remains HTTP transport and is no longer a workflow payload
1212
codec.
1313
Earlier SDK versions remain historical releases and are not alternate supported
@@ -56,6 +56,10 @@ Earlier SDK versions remain historical releases and are not alternate supported
5656
`NamespaceDescription.deleted`.
5757

5858
### Fixed
59+
- Explicit JSON and unknown payload-codec tags now fail closed before null,
60+
absent, empty-argument, or already-decoded replay shortcuts. Untagged
61+
no-payload sentinels and Avro-encoded null values retain their intended
62+
behavior.
5963
- The Python API reference now describes query decorators and query-state
6064
replay as parts of the shipped server-routed worker query path while keeping
6165
its Server capability negotiation requirements explicit.

‎pyproject.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "durable-workflow"
7-
version = "2.0.0-rc.30"
7+
version = "2.0.0-rc.31"
88
description = "Release candidate Python SDK for the Durable Workflow 2.0 train"
99
readme = "README.md"
1010
requires-python = ">=3.10"
@@ -68,8 +68,8 @@ durable-workflow-replay-conformance = "durable_workflow.replay_conformance:main"
6868
durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updates_conformance:main"
6969

7070
[tool.durable-workflow]
71-
product-train = "2.0.0-rc.30"
72-
registry-version = "2.0.0rc30"
71+
product-train = "2.0.0-rc.31"
72+
registry-version = "2.0.0rc31"
7373
supported-server-versions = "2.0.0-rc.32"
7474
worker-protocol-version = "1.1"
7575
control-plane-version = "2"

‎scripts/ci/run-codec-regression-fixture.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def execute_fixture(fixture: dict[str, Any], codec: Any) -> None:
4747
from durable_workflow import serializer
4848

4949
wire = base64.b64decode(fixture["framing"]["wire_base64"], validate=True).decode("utf-8")
50+
blob = None if fixture["value"]["type"] == "null" else wire
5051
try:
51-
serializer.decode_envelope({"codec": "json", "blob": wire})
52+
serializer.decode_envelope({"codec": "json", "blob": blob})
5253
except ValueError as caught:
5354
_require(
5455
fixture["failure_policy"]

‎src/durable_workflow/serializer.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,15 @@ def decode_envelope(
458458
decoder. Untagged raw durable payload blobs are rejected. External payload
459459
references require an *external_storage* driver and verify size/hash before decode.
460460
"""
461+
if isinstance(value, dict) and "codec" in value:
462+
_validate_payload_codec(value["codec"])
461463
if isinstance(value, dict) and "codec" in value and "blob" in value:
462464
return decode(value["blob"], codec=value["codec"])
463465
if isinstance(value, dict) and "external_storage" in value:
464466
if external_storage is None:
465467
raise ValueError("external payload reference requires an external storage driver")
466468
reference = ExternalPayloadReference.from_dict(value["external_storage"])
467469
envelope_codec = value.get("codec")
468-
if envelope_codec is not None and envelope_codec != AVRO_CODEC:
469-
raise _unsupported_payload_codec(envelope_codec)
470470
if envelope_codec is not None and envelope_codec != reference.codec:
471471
raise ValueError("external payload reference codec does not match envelope codec")
472472
blob = fetch_external_payload(external_storage, reference, cache=external_storage_cache).decode("utf-8")
@@ -500,7 +500,7 @@ def decode_envelopes(
500500
for index, value in enumerate(values):
501501
if isinstance(value, dict) and "codec" in value and "blob" in value:
502502
jobs.append((value["blob"], value["codec"]))
503-
elif value is None:
503+
elif value is None and codec is None:
504504
passthroughs[index] = None
505505
jobs.append((None, None))
506506
else:
@@ -547,13 +547,18 @@ def decode(blob: str | None, codec: str | None = None) -> Any:
547547
:class:`~durable_workflow.errors.AvroNotInstalledError` when the Avro
548548
runtime dependency is missing from a broken or partial installation.
549549
"""
550+
if blob is None and codec is None:
551+
return None
552+
553+
_validate_payload_codec(codec)
550554
if blob is None:
551555
return None
556+
return _avro.decode(blob)
552557

553-
if codec == AVRO_CODEC:
554-
return _avro.decode(blob)
555558

556-
raise _unsupported_payload_codec(codec)
559+
def _validate_payload_codec(codec: object) -> None:
560+
if codec != AVRO_CODEC:
561+
raise _unsupported_payload_codec(codec)
557562

558563

559564
def _unsupported_payload_codec(codec: object) -> ValueError:

‎src/durable_workflow/workflow.py‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from collections.abc import Callable, Iterable, Mapping, Sequence
2828
from dataclasses import dataclass, field
2929
from datetime import datetime, timezone
30-
from typing import Any, TypeVar
30+
from typing import Any, TypeVar, cast
3131

3232
from . import serializer
3333
from .errors import (
@@ -1582,14 +1582,28 @@ class _RecordedStep:
15821582
details: dict[str, Any]
15831583

15841584

1585+
def _validated_replay_payload_codec(
1586+
payload: Mapping[str, Any],
1587+
fallback_codec: str | None,
1588+
) -> str | None:
1589+
explicit = "payload_codec" in payload
1590+
codec = cast(
1591+
str | None,
1592+
payload["payload_codec"] if explicit else fallback_codec,
1593+
)
1594+
if (explicit or codec is not None) and codec != serializer.AVRO_CODEC:
1595+
serializer.decode("", codec=codec)
1596+
return codec
1597+
1598+
15851599
def _decode_history_result(
15861600
payload: dict[str, Any],
15871601
fallback_codec: str | None,
15881602
*,
15891603
external_storage: ExternalStorageDriver | None = None,
15901604
external_storage_cache: ExternalPayloadCache | None = None,
15911605
) -> Any:
1592-
codec = payload.get("payload_codec") or fallback_codec
1606+
codec = _validated_replay_payload_codec(payload, fallback_codec)
15931607
value = payload["result"] if "result" in payload else payload.get("output")
15941608

15951609
return serializer.decode_envelope(
@@ -1615,7 +1629,7 @@ def _decode_signal_args(
16151629
external_storage: ExternalStorageDriver | None = None,
16161630
external_storage_cache: ExternalPayloadCache | None = None,
16171631
) -> list[Any]:
1618-
codec = payload.get("payload_codec") or fallback_codec
1632+
codec = _validated_replay_payload_codec(payload, fallback_codec)
16191633
raw = payload.get("value")
16201634
if raw is None:
16211635
raw = payload.get("input")
@@ -1641,7 +1655,7 @@ def _decode_update_args(
16411655
external_storage: ExternalStorageDriver | None = None,
16421656
external_storage_cache: ExternalPayloadCache | None = None,
16431657
) -> list[Any]:
1644-
codec = payload.get("payload_codec") or fallback_codec
1658+
codec = _validated_replay_payload_codec(payload, fallback_codec)
16451659
raw = payload.get("arguments")
16461660
if raw is None:
16471661
return []
@@ -1734,7 +1748,7 @@ def _start_input_from_history(
17341748
payload = event.get("payload") or {}
17351749
if not isinstance(payload, Mapping):
17361750
return []
1737-
codec = payload.get("payload_codec") or payload_codec
1751+
codec = _validated_replay_payload_codec(payload, payload_codec)
17381752
for key in ("input_envelope", "input", "arguments"):
17391753
raw = payload.get(key)
17401754
if raw is None:
@@ -1772,7 +1786,10 @@ def _decode_receiver_args(
17721786
payload = event.get("payload") or {}
17731787
if not isinstance(payload, Mapping):
17741788
payload = {}
1775-
codec = payload.get("payload_codec") or payload_codec
1789+
codec = cast(
1790+
str | None,
1791+
payload.get("payload_codec", payload_codec),
1792+
)
17761793
try:
17771794
if receiver_kind == "signal":
17781795
return _decode_signal_args(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json",
3+
"fixture_schema": "durable-workflow.codec-regression/v1",
4+
"id": "json-tagged-null-payload-codec-rejected",
5+
"protocol": {
6+
"codec": "json",
7+
"schema": "durable_workflow.protocol.Value",
8+
"version": "1",
9+
"fingerprint": null
10+
},
11+
"bindings": [
12+
"python"
13+
],
14+
"value": {
15+
"type": "null"
16+
},
17+
"framing": {
18+
"encoding": "utf8-json",
19+
"wire_base64": "bnVsbA=="
20+
},
21+
"failure_policy": {
22+
"operation": "decode_reject",
23+
"error": "unsupported_payload_codec"
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json",
3+
"fixture_schema": "durable-workflow.replay-regression/v1",
4+
"id": "json-tagged-empty-workflow-start-rejected",
5+
"protocol_version": "1.1",
6+
"bindings": [
7+
"python"
8+
],
9+
"workflow": {
10+
"type": "golden.signal-wait",
11+
"payload_codec": "avro"
12+
},
13+
"history": [
14+
{
15+
"event_type": "WorkflowStarted",
16+
"payload": {
17+
"workflow_type": "golden.signal-wait",
18+
"payload_codec": "json"
19+
}
20+
}
21+
],
22+
"expected": {
23+
"error": "unsupported_payload_codec"
24+
}
25+
}

‎tests/test_api_reference_install.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def run_requirement(
186186
]
187187

188188

189-
def test_public_rc24_does_not_mask_an_unpublished_exact_rc30(
189+
def test_public_rc24_does_not_mask_an_unpublished_exact_rc31(
190190
monkeypatch: pytest.MonkeyPatch,
191191
) -> None:
192192
identity = load_release_identity(REPO_ROOT)
@@ -205,26 +205,26 @@ def run_requirement(
205205
raise PublicRequirementUnavailable(1, ["pip", "install", requirement])
206206
raise subprocess.CalledProcessError(
207207
1,
208-
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc30"],
208+
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc31"],
209209
)
210210

211211
monkeypatch.setattr("scripts.check_api_reference_install._run_clean_requirement", run_requirement)
212212

213213
with pytest.raises(PublicRequirementUnavailable):
214214
run_clean_install(identity.requirement, identity, install_attempts=1, install_retry_sleep=0)
215215

216-
assert identity.registry_version == "2.0.0rc30"
216+
assert identity.registry_version == "2.0.0rc31"
217217
assert calls == [identity.exact_requirement]
218218

219219

220-
def test_stale_documented_range_is_a_hard_failure_after_exact_rc30_exists(
220+
def test_stale_documented_range_is_a_hard_failure_after_exact_rc31_exists(
221221
monkeypatch: pytest.MonkeyPatch,
222222
) -> None:
223223
identity = load_release_identity(REPO_ROOT)
224224
calls: list[str] = []
225225
stale_range = subprocess.CalledProcessError(
226226
1,
227-
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc30"],
227+
["python", "-c", "installed durable-workflow 2.0.0rc24, expected 2.0.0rc31"],
228228
)
229229

230230
def run_requirement(

‎tests/test_pypi_project_surface.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323

2424
def source_metadata(*, stable: bool = False) -> SourceMetadata:
25-
version = "2.0.0" if stable else "2.0.0-rc.30"
26-
registry_version = "2.0.0" if stable else "2.0.0rc30"
25+
version = "2.0.0" if stable else "2.0.0-rc.31"
26+
registry_version = "2.0.0" if stable else "2.0.0rc31"
2727
return SourceMetadata(
2828
commit="a" * 40,
2929
name="durable-workflow",
@@ -163,7 +163,7 @@ def resolve(requirement: str, *, prerelease: bool) -> object:
163163
monkeypatch.setattr("scripts.check_pypi_project_surface._pip_report", resolve)
164164
monkeypatch.setattr("scripts.check_pypi_project_surface.time.sleep", sleeps.append)
165165

166-
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc23; expected 2.0.0rc30"):
166+
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc23; expected 2.0.0rc31"):
167167
main(["--source-ref", "release-source", "--attempts", "30", "--interval-seconds", "10"])
168168

169169
assert requirements == [
@@ -191,14 +191,14 @@ def run_pip(command: list[str], **_: object) -> subprocess.CompletedProcess[str]
191191
if "==" in requirement and pip_attempts[requirement] == 1:
192192
detail = (
193193
f"ERROR: Could not find a version that satisfies the requirement {requirement} "
194-
"(from versions: 0.4.106, 2.0.0rc29)\n"
194+
"(from versions: 0.4.106, 2.0.0rc30)\n"
195195
f"ERROR: No matching distribution found for {requirement}\n"
196196
)
197197
return subprocess.CompletedProcess(command, 1, stdout="", stderr=detail)
198198

199199
version = source.registry_version
200200
if "~=" in requirement and pip_attempts[requirement] == 1:
201-
version = "2.0.0rc29"
201+
version = "2.0.0rc30"
202202
report_path = Path(command[command.index("--report") + 1])
203203
report_path.write_text(json.dumps(pip_report(version)), encoding="utf-8")
204204
return subprocess.CompletedProcess(command, 0, stdout="", stderr="")
@@ -262,7 +262,7 @@ def test_exact_pip_semantic_mismatch_fails_without_retrying(monkeypatch: pytest.
262262
)
263263
monkeypatch.setattr("scripts.check_pypi_project_surface.time.sleep", sleeps.append)
264264

265-
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc24; expected 2.0.0rc30"):
265+
with pytest.raises(ProjectSurfaceError, match="pip selected 2.0.0rc24; expected 2.0.0rc31"):
266266
main(["--source-ref", "release-source", "--attempts", "30", "--interval-seconds", "10"])
267267

268268
assert requirements == [f"{source.name}=={source.registry_version}"]

‎tests/test_release_docs_source.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
REPO_ROOT = Path(__file__).resolve().parents[1]
77
VALIDATOR = REPO_ROOT / "scripts" / "ci" / "validate-release-docs-source.py"
8-
VERSION = "2.0.0-rc.30"
8+
VERSION = "2.0.0-rc.31"
99

1010

1111
def git(repo: Path, *arguments: str) -> str:

0 commit comments

Comments
 (0)