Skip invalid notes CLI item rows (#2005)
This commit is contained in:
parent
dff79319d7
commit
a326a6a555
2 changed files with 25 additions and 1 deletions
|
|
@ -36,7 +36,9 @@ def _load_items(raw) -> list:
|
||||||
items = json.loads(raw)
|
items = json.loads(raw)
|
||||||
except (TypeError, json.JSONDecodeError):
|
except (TypeError, json.JSONDecodeError):
|
||||||
return []
|
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:
|
def _serialize(n: "Note") -> dict:
|
||||||
|
|
|
||||||
|
|
@ -46,3 +46,25 @@ def test_serialize_keeps_list_note_items(monkeypatch):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert cli._serialize(note)["items"] == [{"text": "done"}]
|
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"}]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue