Skip to content
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
2 changes: 1 addition & 1 deletion src/fedcourtsai/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ def _from_record(record: RecordRow) -> CorpusRow:
disposition=record["disposition"],
judges=json.loads(record["judges"]),
panel=[PanelMember(**m) for m in json.loads(record["panel"])],
counsel=[CounselEntry(**c) for c in json.loads(record["counsel"])],
counsel=[CounselEntry(**c) for c in json.loads(_optional_str(record, "counsel") or "[]")],
parties=json.loads(record["parties"]),
attorneys=json.loads(record["attorneys"]),
topic=record["topic"],
Expand Down
21 changes: 21 additions & 0 deletions tests/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,27 @@ def test_the_sibling_letter_forms_take_the_same_tolerances() -> None:
assert corpus.is_disbarment_docket(_scotus("16D02977"))


def test_counsel_reads_empty_from_a_blob_that_predates_the_column(tmp_path: Path) -> None:
"""The ranged and service backends read the published blob as-is — no
``connect`` migration runs — so a column the blob predates must read as its
default through ``_from_record``, the same contract every ``_optional_*``
column honors."""
db = tmp_path / "corpus.db"
with corpus.connect(db) as conn:
corpus.upsert_rows(conn, [_row("scotus/886")])

raw = sqlite3.connect(db)
try:
raw.execute("ALTER TABLE cases DROP COLUMN counsel")
raw.commit()
raw.row_factory = sqlite3.Row
record = raw.execute("SELECT * FROM cases WHERE case_id = 'scotus/886'").fetchone()
row = corpus._from_record(record)
finally:
raw.close()
assert row.counsel == []


def test_counsel_round_trips_with_its_side(tmp_path: Path) -> None:
"""The side is the reason the column exists, so it is the thing that must
survive storage — a round trip that kept only the names would be the flat
Expand Down