mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-30 08:32:07 -04:00
Skip invalid notes CLI item rows (#2005)
This commit is contained in:
@@ -36,7 +36,9 @@ def _load_items(raw) -> list:
|
||||
items = json.loads(raw)
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
return []
|
||||
return items if isinstance(items, list) else []
|
||||
if not isinstance(items, list):
|
||||
return []
|
||||
return [item for item in items if isinstance(item, dict)]
|
||||
|
||||
|
||||
def _serialize(n: "Note") -> dict:
|
||||
|
||||
@@ -46,3 +46,25 @@ def test_serialize_keeps_list_note_items(monkeypatch):
|
||||
)
|
||||
|
||||
assert cli._serialize(note)["items"] == [{"text": "done"}]
|
||||
|
||||
|
||||
def test_serialize_skips_invalid_note_item_rows(monkeypatch):
|
||||
make_core_db_stub(monkeypatch, models=["Note"])
|
||||
cli = load_script("odysseus-notes")
|
||||
note = SimpleNamespace(
|
||||
id="n1",
|
||||
title="Checklist",
|
||||
content="",
|
||||
items='[{"text": "done"}, "bad", null, 3]',
|
||||
note_type="checklist",
|
||||
color=None,
|
||||
label=None,
|
||||
pinned=False,
|
||||
archived=False,
|
||||
due_date=None,
|
||||
source=None,
|
||||
created_at=None,
|
||||
updated_at=None,
|
||||
)
|
||||
|
||||
assert cli._serialize(note)["items"] == [{"text": "done"}]
|
||||
|
||||
Reference in New Issue
Block a user