Skip to content

Commit

Permalink
Bugfix/signal instance raw (Netflix#3072)
Browse files Browse the repository at this point in the history
* Allow for casting for signal instance id
  • Loading branch information
kevgliss authored and rutvijmehta-harness committed Mar 17, 2023
1 parent 989665f commit fea9b63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
)
from slack_bolt import Ack, BoltContext, Respond
from slack_sdk.web.client import WebClient
from sqlalchemy.orm import Session
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session

from dispatch.auth.models import DispatchUser
from dispatch.case import flows as case_flows
Expand Down Expand Up @@ -71,7 +71,7 @@
from dispatch.project import service as project_service
from dispatch.search.utils import create_filter_expression
from dispatch.signal import service as signal_service
from dispatch.signal.models import SignalUpdate, SignalFilterCreate, SignalFilterRead
from dispatch.signal.models import SignalFilterCreate, SignalFilterRead, SignalUpdate


def configure(config: SlackConversationConfiguration):
Expand Down Expand Up @@ -1315,7 +1315,9 @@ def signal_button_click(
ack: Ack, body: dict, db_session: Session, context: BoltContext, client: WebClient
):
ack()
signal = signal_service.get(db_session=db_session, signal_id=context["subject"].id)
signal = signal_service.get_signal_instance(
db_session=db_session, signal_instance_id=context["subject"].id
)

blocks = [Section(text=f"```{json.dumps(signal.raw, indent=2)}```")]

Expand Down
14 changes: 13 additions & 1 deletion src/dispatch/signal/service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import json
from sqlalchemy_utils import cast_if

from datetime import datetime, timedelta, timezone
from typing import Optional, Literal

from pydantic.error_wrappers import ErrorWrapper, ValidationError
from sqlalchemy import asc
from sqlalchemy import asc, String
from sqlalchemy.orm import Session


from dispatch.auth.models import DispatchUser
from dispatch.case.priority import service as case_priority_service
from dispatch.case.type import service as case_type_service
Expand Down Expand Up @@ -118,6 +121,15 @@ def get_signal_filter(*, db_session: Session, signal_filter_id: int) -> SignalFi
return db_session.query(SignalFilter).filter(SignalFilter.id == signal_filter_id).one_or_none()


def get_signal_instance(*, db_session: Session, signal_instance_id: int | str):
"""Gets a signal instance by it's UUID."""
return (
db_session.query(SignalInstance)
.filter(SignalInstance.id == cast_if(signal_instance_id, String))
.one_or_none()
)


def get(*, db_session: Session, signal_id: int) -> Optional[Signal]:
"""Gets a signal by id."""
return db_session.query(Signal).filter(Signal.id == signal_id).one_or_none()
Expand Down

0 comments on commit fea9b63

Please sign in to comment.