Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 500 on panorama building save (for real this time) #622

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading