3
0
Fork 0

fix: prevent error in DateTime schema type if no widget/request set

when we use this intentionally, the widget/request should be set as
expected. but apparently this gets instantiated sometimes (by
ColanderAlchemy?) without a widget.

so this adds sane fallback logic, instead of outright error
This commit is contained in:
Lance Edgar 2025-12-17 17:46:31 -06:00
parent 131eb22580
commit 2ccfe29553
2 changed files with 28 additions and 9 deletions

View file

@ -62,6 +62,13 @@ class TestWuttaDateTime(WebTestCase):
)
self.assertEqual(result, "2024-12-11 02:33 PM")
# missing widget/request/config
typ = mod.WuttaDateTime()
node = colander.SchemaNode(typ)
result = typ.serialize(node, datetime.datetime(2024, 12, 11, 22, 33))
# nb. not possible to know which timezone is system-local
self.assertTrue(result.startswith("2024-12-"))
def test_deserialize(self):
tzlocal = get_timezone_by_name("America/Los_Angeles")
with patch.object(self.app, "get_timezone", return_value=tzlocal):