Skip to content

Commit

Permalink
Fix 500 on panorama building save (for real this time) (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Oct 12, 2024
1 parent 0014070 commit d158dcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/meshapi/tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.test import TestCase

from meshapi.widgets import PanoramaViewer


class TestPanoramaViewer(TestCase):
def setUp(self):
pass

def test_pano_get_context(self):
PanoramaViewer.pano_get_context("test", '["blah", "blah2"]')

def test_pano_get_context_bad_value(self):
PanoramaViewer.pano_get_context("test", 100) # type: ignore
PanoramaViewer.pano_get_context("test", None) # type: ignore
11 changes: 9 additions & 2 deletions src/meshapi/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from typing import Any, Callable, Dict, Optional

from django import forms
Expand All @@ -15,8 +16,14 @@ class PanoramaViewer(JSONFormWidget):
def __init__(self, schema: dict):
super().__init__(schema)

def pano_get_context(self, name: str, value: str = "[]") -> dict:
value_as_array = json.loads(value)
@staticmethod
def pano_get_context(name: str, value: str) -> dict:
try:
value_as_array = json.loads(value) if value else ""
except TypeError:
logging.exception("Got bad value when trying to make panorama array.")
value_as_array = ""

return {
"widget": {
"name": name,
Expand Down

0 comments on commit d158dcc

Please sign in to comment.