fix(webhooks): JSONB-Containment statt .any() auf JSON-Spalte — behebt 158 fehlgeschlagene Outbox-Events
This commit is contained in:
@@ -7,7 +7,8 @@ import logging
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import cast, select
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from app.core.db import get_session_factory
|
||||
from app.core.event_bus import EventBus, get_event_bus
|
||||
@@ -48,7 +49,12 @@ async def _dispatch_event(payload: dict[str, Any]) -> None:
|
||||
stmt = select(Webhook).where(
|
||||
Webhook.tenant_id == tenant_id,
|
||||
Webhook.is_active == True, # noqa: E712
|
||||
Webhook.events.any(event_name),
|
||||
# Webhook.events is a JSONB array column (NOT a relationship):
|
||||
# events @> '["<event_name>"]' — JSONB containment instead of
|
||||
# the invalid relationship .any() call that crashed every event
|
||||
# with "Neither 'AnnotatedColumn' nor 'Comparator' object has an
|
||||
# attribute 'any'" (158 failed outbox events in production).
|
||||
cast(Webhook.events, JSONB).contains([event_name]),
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
webhooks = list(result.scalars().all())
|
||||
|
||||
Reference in New Issue
Block a user