feat: add raw_json() to the event returned by webhook verification - #652
Closed
razor-x wants to merge 1 commit into
Closed
feat: add raw_json() to the event returned by webhook verification#652razor-x wants to merge 1 commit into
razor-x wants to merge 1 commit into
Conversation
from_dict reads only the properties it was generated for, so a field Seam adds to an existing event between SDK releases is silently discarded. #651 made parsing degrade instead of raise, but did not keep the payload, so there was no way to reach a new field short of upgrading. SeamWebhook.verify() now returns an event carrying raw_json(): json.loads(event.raw_json())["a_field_this_version_predates"] DeepAttrDict answers the same call, so the unrecognized-event branch and the typed branch are handled the same way. This matters because the fallback is not otherwise interchangeable with a generated event: reading a missing key raises AttributeError where a dataclass returns None, so generic code written against the declared union breaks on it. Scoped to events. It is there for the verify return, not as a general accessor on every model. A method rather than a property because the call is where the serialization happens; the event retains the decoded payload and serializes on demand. The retained payload is repr=False and compare=False, so it changes neither the repr nor equality. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M2kJ4nGaM8imZCVMEKjmXA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #651. That PR made parsing degrade instead of raise, but it did not keep the payload — so this is the half that actually lets a handler reach something the SDK does not know about yet.
The gap
from_dictreads only the properties it was generated for, so a field Seam adds to an existing event between SDK releases is silently discarded:There was no way to recover it short of upgrading the SDK.
The change
SeamWebhook.verify()now returns an event carryingraw_json():DeepAttrDictanswers the same call, so the unrecognized-event branch and the typed branch are handled the same way. That matters more than it first appears: the fallback is not otherwise interchangeable with a generated event, because reading a missing key raisesAttributeErrorwhere a dataclass returnsNone. Generic code written against the declared union breaks on it:raw_json()gives both branches one thing that always works.Scope
Events only. It exists for the
verifyreturn, not as a general accessor on every model —Device, action attempts and the rest are untouched, and there is a test pinning that.A method rather than a property because the call is where the serialization happens: the event retains the decoded payload and serializes on demand. The retained payload is
repr=Falseandcompare=False, so it changes neither the repr nor equality.Verification
just lint && just test— 289 tests, mypy clean, pylint 10.00/10, black clean.New tests cover recovering a dropped field, round-tripping a known and an unrecognized event, absence from the repr, equality being unaffected, and
raw_jsonnot leaking onto non-event models.🤖 Generated with Claude Code
https://claude.ai/code/session_01M2kJ4nGaM8imZCVMEKjmXA
Generated by Claude Code