Skip to content

Commit d46eb39

Browse files
authored
Do not serialize raw Action objects and their callable (fixes #136, #137) (#139)
* Do not serialize raw Action objects and their callable (fixes #137) * Make pylint happy * Exclude field at model level (:facepalm)
1 parent 7dabfdc commit d46eb39

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/app/api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import sentry_sdk
1111
import uvicorn # type: ignore
1212
from fastapi import Body, Depends, FastAPI, Request
13-
from fastapi.encoders import jsonable_encoder
1413
from fastapi.responses import HTMLResponse
1514
from fastapi.staticfiles import StaticFiles
1615
from fastapi.templating import Jinja2Templates
@@ -104,14 +103,16 @@ def bugzilla_webhook(
104103

105104

106105
@app.get("/whiteboard_tags/")
107-
def get_whiteboard_tag(
106+
def get_whiteboard_tags(
108107
whiteboard_tag: Optional[str] = None,
109108
actions: Actions = Depends(configuration.get_actions),
110109
):
111110
"""API for viewing whiteboard_tags and associated data"""
112111
if existing := actions.get(whiteboard_tag):
113-
return {whiteboard_tag: existing}
114-
return actions.by_tag
112+
filtered = {whiteboard_tag: existing}
113+
else:
114+
filtered = actions.by_tag # type: ignore
115+
return {k: v.dict() for k, v in filtered.items()}
115116

116117

117118
@app.get("/jira_projects/")
@@ -131,7 +132,7 @@ def powered_by_jbi(
131132
context = {
132133
"request": request,
133134
"title": "Powered by JBI",
134-
"actions": jsonable_encoder(actions),
135+
"actions": [action.dict() for action in actions],
135136
"enable_query": enabled,
136137
}
137138
return templates.TemplateResponse("powered_by_template.html", context)

src/jbi/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Config:
5656

5757
extra = Extra.allow
5858
keep_untouched = (functools.cached_property,)
59+
fields = {"callable": {"exclude": True}}
5960

6061

6162
class Actions(YamlModel):

0 commit comments

Comments
 (0)