Skip to content

Commit 50d0d0a

Browse files
fix(sse-api): handle None fullDocument in hub cache change stream (#3336)
* fix(sse-api): handle None fullDocument in hub cache change stream Delete events can omit fullDocument; always branch deletes and guard non-delete paths before accessing fullDocument.kind to avoid TypeError. Co-authored-by: Cursor <cursoragent@cursor.com> * chore(sse-api): ruff format watcher.py Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 82f88ce commit 50d0d0a

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

services/sse-api/src/sse_api/watcher.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,15 @@ async def _watch_loop(self) -> None:
188188
async for change in stream:
189189
resume_token = stream.resume_token
190190
operation = change["operationType"]
191-
if (
192-
operation == "delete"
193-
and "fullDocumentBeforeChange" in change
194-
and change["fullDocumentBeforeChange"]["kind"] == HUB_CACHE_KIND
195-
):
196-
dataset = change["fullDocumentBeforeChange"]["dataset"]
197-
self._publisher._notify_change(dataset=dataset, hub_cache=None)
191+
if operation == "delete":
192+
before = change.get("fullDocumentBeforeChange")
193+
if before and before.get("kind") == HUB_CACHE_KIND:
194+
dataset = before["dataset"]
195+
self._publisher._notify_change(dataset=dataset, hub_cache=None)
198196
continue
199197

200-
if change["fullDocument"]["kind"] != HUB_CACHE_KIND:
198+
full_document = change.get("fullDocument")
199+
if not full_document or full_document.get("kind") != HUB_CACHE_KIND:
201200
continue
202201

203202
updated_fields = (change.get("updateDescription") or {}).get("updatedFields") or {}
@@ -208,11 +207,9 @@ async def _watch_loop(self) -> None:
208207
continue
209208

210209
self._publisher._notify_change(
211-
dataset=change["fullDocument"]["dataset"],
210+
dataset=full_document["dataset"],
212211
hub_cache=(
213-
change["fullDocument"]["content"]
214-
if change["fullDocument"]["http_status"] == HTTPStatus.OK
215-
else None
212+
full_document["content"] if full_document["http_status"] == HTTPStatus.OK else None
216213
),
217214
)
218215
except PyMongoError as exc:

0 commit comments

Comments
 (0)