Skip to content

Commit 17fa362

Browse files
committed
[py] warn once per record for undeclared BiDi properties, not once per key
1 parent 23d0038 commit 17fa362

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

py/selenium/webdriver/common/_bidi/serialization.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,14 @@ def from_json(cls, payload: dict) -> Any:
274274
continue
275275
kwargs[f.name] = _read_field(cls, f.name, w, payload)
276276
undeclared = [k for k in payload if k not in known]
277-
for key in undeclared:
278-
# A property the type does not declare is tolerated for forward-compatibility
279-
# (ADR decision 2.3): warned, and kept only on an extensible (re-sendable) type
280-
# so a caller can echo it back on the wire — otherwise dropped.
281-
_tolerate(f"{cls.__name__}: undeclared property {key!r} ({'kept' if cls._EXTENSIBLE else 'dropped'})")
277+
if undeclared:
278+
# Properties the type does not declare are tolerated for forward-compatibility
279+
# (ADR decision 2.3): warned once for the whole record — not once per key, so a
280+
# verbose payload cannot flood the log — and kept only on an extensible
281+
# (re-sendable) type so a caller can echo them back on the wire, else dropped.
282+
noun = "property" if len(undeclared) == 1 else "properties"
283+
names = ", ".join(repr(k) for k in undeclared)
284+
_tolerate(f"{cls.__name__}: undeclared {noun} {names} ({'kept' if cls._EXTENSIBLE else 'dropped'})")
282285
if cls._EXTENSIBLE:
283286
kwargs["extensions"] = {k: payload[k] for k in undeclared}
284287
return cls(**kwargs)

py/test/unit/selenium/webdriver/common/bidi_serialization_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,16 @@ def test_strict_inbound_escalates_an_undeclared_property_to_an_error():
403403
Point.from_json({"x": 1, "y": 2, "z": 3})
404404

405405

406+
def test_many_undeclared_properties_warn_once_for_the_record_not_once_per_key(caplog):
407+
with caplog.at_level(logging.WARNING):
408+
Point.from_json({"x": 1, "y": 2, "a": 1, "b": 2, "c": 3})
409+
undeclared_warnings = [r for r in caplog.records if "undeclared" in r.getMessage()]
410+
assert len(undeclared_warnings) == 1
411+
assert "a" in caplog.text
412+
assert "b" in caplog.text
413+
assert "c" in caplog.text
414+
415+
406416
# --- union dispatch: inbound ---
407417

408418

0 commit comments

Comments
 (0)