@davoodmehraban89 / Aram-2 Mirror · read-only / commits / a661423
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 14:15 UTC

feat(source): content-addressed byte store + full CSV support (D-06)

- SourceFile model (sha256 PK, size, content_type, stored_path) + SourceDocument FK; SourceStore writes immutable bytes atomically, re-verifies hash on read (corruption/tamper fails loudly); registration accepts optional store, keeps metadata-only model contract (accepted tests unchanged) - CSV ledger parser: UTF-8/UTF-8-BOM/Windows-1256, delimiter sniffing, same Persian normalization + exact-money rules as XLSX; parse_ledger routes by extension; streaming reader - Migration 20261203_03 (guarded create + batch add column) Tests: store round-trip/idempotency/corruption, registration+re-import hash match, CSV encodings/delimiters/leading-zeros/missing-header/empty/routing. 185 passed. No source data changed. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

davoodmehraban89 committed Dec 3, 2026 at 09:18 UTC a6614231bdf3fdd380fb97c79ac3383f224e804e
7 files changed +438 -36
backend/migrations/versions/20261203_03_source_file_store.py new
+42
@@ -0,0 +1,42 @@
1 +"""Content-addressed source file storage (D-06).
2 +
3 +Revision ID: 20261203_03
4 +Revises: 20261203_02
5 +"""
6 +
7 +import sqlalchemy as sa
8 +from alembic import op
9 +
10 +from aram_backend.models import SourceFile
11 +
12 +revision = "20261203_03"
13 +down_revision = "20261203_02"
14 +branch_labels = None
15 +depends_on = None
16 +
17 +
18 +def upgrade() -> None:
19 + bind = op.get_bind()
20 + inspector = sa.inspect(bind)
21 + if "source_files" not in inspector.get_table_names():
22 + SourceFile.__table__.create(bind=bind)
23 + columns = {c["name"] for c in inspector.get_columns("source_documents")}
24 + if "source_file_hash" not in columns:
25 + with op.batch_alter_table("source_documents") as batch:
26 + batch.add_column(
27 + sa.Column(
28 + "source_file_hash",
29 + sa.String(64),
30 + sa.ForeignKey("source_files.sha256", ondelete="RESTRICT"),
31 + nullable=True,
32 + )
33 + )
34 +
35 +
36 +def downgrade() -> None:
37 + with op.batch_alter_table("source_documents") as batch:
38 + batch.drop_column("source_file_hash")
39 + bind = op.get_bind()
40 + inspector = sa.inspect(bind)
41 + if "source_files" in inspector.get_table_names():
42 + op.drop_table("source_files")
backend/src/aram_backend/ingestion.py
+33 -4
@@ -6,7 +6,8 @@ from pathlib import Path
6 from sqlalchemy import select
7 from sqlalchemy.orm import Session
8
9 -from aram_backend.models import FiscalYear, FiscalYearStatus, SourceDocument
9 +from aram_backend.models import FiscalYear, FiscalYearStatus, SourceDocument, SourceFile
10 +from aram_backend.services.source_store import SourceStore
11
12
13 ALLOWED_SOURCE_SUFFIXES = frozenset({".csv", ".xlsx"})
@@ -26,11 +27,14 @@ def register_source_document(
27 filename: str,
28 document_type: str,
29 content: bytes,
30 + store: SourceStore | None = None,
31 ) -> SourceDocument:
30 - """Register immutable source metadata without persisting source bytes.
32 + """Register immutable source metadata; optionally persist bytes (D-06).
33
32 - Re-registering the same bytes for the same fiscal year is idempotent. The
33 - caller owns the transaction and may inspect the returned row before commit.
34 + Re-registering the same bytes for the same fiscal year is idempotent. When a
35 + ``store`` is given, the bytes are written to the content-addressed store and
36 + referenced via ``SourceFile``; the SourceDocument row itself never holds the
37 + payload. The caller owns the transaction.
38 """
39
40 if not filename or "/" in filename or "\\" in filename:
@@ -52,6 +56,27 @@ def register_source_document(
56 )
57
58 file_hash = hashlib.sha256(content).hexdigest()
59 +
60 + stored = None
61 + if store is not None:
62 + stored = store.put(content)
63 + if session.get(SourceFile, stored.sha256) is None:
64 + suffix = Path(safe_name).suffix.lower()
65 + content_type = (
66 + "text/csv"
67 + if suffix == ".csv"
68 + else "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
69 + )
70 + session.add(
71 + SourceFile(
72 + sha256=stored.sha256,
73 + size=stored.size,
74 + content_type=content_type,
75 + stored_path=stored.stored_path,
76 + )
77 + )
78 + session.flush()
79 +
80 existing = session.scalar(
81 select(SourceDocument).where(
82 SourceDocument.year_id == year_id,
@@ -65,6 +90,9 @@ def register_source_document(
90 raise SourceRegistrationError(f"document type mismatch for existing content hash")
91 if existing.filename != safe_name:
92 raise SourceRegistrationError(f"filename mismatch for existing content hash")
93 + if stored is not None and existing.source_file_hash is None:
94 + existing.source_file_hash = stored.sha256
95 + session.flush()
96 return existing
97
98 source = SourceDocument(
@@ -72,6 +100,7 @@ def register_source_document(
100 filename=safe_name,
101 file_hash=file_hash,
102 document_type=document_type,
103 + source_file_hash=stored.sha256 if stored is not None else None,
104 )
105 session.add(source)
106 session.flush()
backend/src/aram_backend/ledger_parser.py
+84 -32
@@ -1,5 +1,7 @@
1 from __future__ import annotations
2
3 +import csv
4 +import io
5 from collections.abc import Iterator
6 from dataclasses import dataclass
7 from decimal import Decimal
@@ -53,15 +55,16 @@ _FIELDS = {
55 "closing": "CLOSING",
56 }
57
58 +_CSV_ENCODINGS = ("utf-8-sig", "utf-8", "cp1256")
59 +
60
61 def parse_general_ledger(content: bytes) -> Iterator[LedgerRecord]:
58 - """Stream typed ledger rows without persisting or calculating values.
62 + """Stream typed XLSX ledger rows without persisting or calculating values.
63
64 Codes are normalized as text (leading zeros preserved, P-03/D-04) and money
65 is decoded to exact Decimal via the shortest round-trip repr (D-04). Header
66 matching is Persian-normalized (D-05).
67 """
64 -
68 inspection = inspect_xlsx(content, document_type="general_ledger")
69 workbook = load_workbook(
70 BytesIO(content), read_only=True, data_only=True, keep_links=False
@@ -81,45 +84,92 @@ def parse_general_ledger(content: bytes) -> Iterator[LedgerRecord]:
84 if value is not None
85 }
86 kol_index = indexes.get(normalize_fa("kol"))
84 -
87 for row_number, values in enumerate(
86 - worksheet.iter_rows(
87 - min_row=inspection.header_row + 1, values_only=True
88 - ),
88 + worksheet.iter_rows(min_row=inspection.header_row + 1, values_only=True),
89 start=inspection.header_row + 1,
90 ):
91 if not any(value is not None for value in values):
92 continue
93 -
94 - def value(field: str):
95 - return values[indexes[normalize_fa(_FIELDS[field])]]
96 -
97 - yield LedgerRecord(
98 - row_number=row_number,
99 - account_code=_required_code(value("account_code"), row_number, "حساب"),
100 - general_code=(
101 - _optional_code(values[kol_index], row_number, "kol")
102 - if kol_index is not None
103 - else None
104 - ),
105 - account_name=_required_text(
106 - value("account_name"), row_number, "ACCOUNT_NAME"
107 - ),
108 - source_year=_required_year(value("source_year"), row_number),
109 - entry_type=_required_text(value("entry_type"), row_number, "نوع"),
110 - t1_code=_optional_code(value("t1_code"), row_number, "T1_CODE"),
111 - t2_code=_optional_code(value("t2_code"), row_number, "T2_CODE"),
112 - t3_code=_optional_code(value("t3_code"), row_number, "T3_CODE"),
113 - t4_code=_optional_code(value("t4_code"), row_number, "T4_CODE"),
114 - opening=_required_decimal(value("opening"), row_number, "OPENING"),
115 - debit=_required_decimal(value("debit"), row_number, "Debit"),
116 - credit=_required_decimal(value("credit"), row_number, "Credit"),
117 - closing=_required_decimal(value("closing"), row_number, "CLOSING"),
118 - )
93 + yield _build_record(values, indexes, kol_index, row_number)
94 finally:
95 workbook.close()
96
97
98 +def parse_general_ledger_csv(content: bytes) -> Iterator[LedgerRecord]:
99 + """Stream typed CSV ledger rows (D-06, booklet §8).
100 +
101 + Supports UTF-8, UTF-8-BOM and Windows-1256; sniffs the delimiter; applies the
102 + same Persian normalization and exact-money rules as the XLSX path. Reading is
103 + streaming (csv.reader over the decoded text), never materializing all rows.
104 + """
105 + text = _decode_csv(content)
106 + sample = text[:4096]
107 + try:
108 + dialect = csv.Sniffer().sniff(sample, delimiters=",\t;")
109 + except csv.Error:
110 + dialect = csv.excel
111 + reader = csv.reader(io.StringIO(text), dialect)
112 + header = next(reader, None)
113 + if header is None:
114 + raise LedgerParseError("CSV ledger is empty")
115 + indexes = {normalize_fa(name): i for i, name in enumerate(header) if name.strip()}
116 + required = {normalize_fa(name) for name in _FIELDS.values()}
117 + missing = required.difference(indexes)
118 + if missing:
119 + raise LedgerParseError(f"CSV ledger is missing required headers: {sorted(missing)}")
120 + kol_index = indexes.get(normalize_fa("kol"))
121 + for row_number, values in enumerate(reader, start=2):
122 + if not any(value.strip() for value in values):
123 + continue
124 + yield _build_record(values, indexes, kol_index, row_number)
125 +
126 +
127 +def parse_ledger(content: bytes, filename: str) -> Iterator[LedgerRecord]:
128 + """Route to the XLSX or CSV parser by file extension (D-06)."""
129 + lower = filename.lower()
130 + if lower.endswith(".csv"):
131 + return parse_general_ledger_csv(content)
132 + if lower.endswith(".xlsx"):
133 + return parse_general_ledger(content)
134 + raise LedgerParseError("only .xlsx and .csv ledger files are supported")
135 +
136 +
137 +def _decode_csv(content: bytes) -> str:
138 + for encoding in _CSV_ENCODINGS:
139 + try:
140 + return content.decode(encoding)
141 + except UnicodeDecodeError:
142 + continue
143 + raise LedgerParseError("CSV encoding must be UTF-8, UTF-8-BOM, or Windows-1256")
144 +
145 +
146 +def _build_record(values, indexes, kol_index, row_number) -> LedgerRecord:
147 + def value(field: str):
148 + i = indexes[normalize_fa(_FIELDS[field])]
149 + return values[i] if i < len(values) else None
150 +
151 + return LedgerRecord(
152 + row_number=row_number,
153 + account_code=_required_code(value("account_code"), row_number, "حساب"),
154 + general_code=(
155 + _optional_code(values[kol_index], row_number, "kol")
156 + if kol_index is not None and kol_index < len(values)
157 + else None
158 + ),
159 + account_name=_required_text(value("account_name"), row_number, "ACCOUNT_NAME"),
160 + source_year=_required_year(value("source_year"), row_number),
161 + entry_type=_required_text(value("entry_type"), row_number, "نوع"),
162 + t1_code=_optional_code(value("t1_code"), row_number, "T1_CODE"),
163 + t2_code=_optional_code(value("t2_code"), row_number, "T2_CODE"),
164 + t3_code=_optional_code(value("t3_code"), row_number, "T3_CODE"),
165 + t4_code=_optional_code(value("t4_code"), row_number, "T4_CODE"),
166 + opening=_required_decimal(value("opening"), row_number, "OPENING"),
167 + debit=_required_decimal(value("debit"), row_number, "Debit"),
168 + credit=_required_decimal(value("credit"), row_number, "Credit"),
169 + closing=_required_decimal(value("closing"), row_number, "CLOSING"),
170 + )
171 +
172 +
173 def _required_text(value: object, row_number: int, field: str) -> str:
174 text = normalize_fa(str(value)) if value is not None else ""
175 if not text:
@@ -144,6 +194,8 @@ def _required_code(value: object, row_number: int, field: str) -> str:
194 def _optional_code(value: object, row_number: int, field: str) -> str | None:
195 if value is None:
196 return None
197 + if isinstance(value, str) and not value.strip():
198 + return None
199 try:
200 return normalize_code(value, row=row_number, field=field)
201 except NormalizationError as exc:
backend/src/aram_backend/models.py
+17
@@ -78,6 +78,20 @@ class YearOwnedMixin:
78 year_id: Mapped[int] = mapped_column(ForeignKey("fiscal_years.id", ondelete="RESTRICT"), index=True)
79
80
81 +class SourceFile(TimestampMixin, Base):
82 + """Content-addressed source bytes stored on disk (D-06, booklet §5).
83 +
84 + The primary key is the SHA-256 of the bytes; ``stored_path`` points at the
85 + immutable file in the content-addressed store. SourceDocument references it.
86 + """
87 +
88 + __tablename__ = "source_files"
89 + sha256: Mapped[str] = mapped_column(String(64), primary_key=True)
90 + size: Mapped[int] = mapped_column(Integer)
91 + content_type: Mapped[str] = mapped_column(String(64), default="")
92 + stored_path: Mapped[str] = mapped_column(String(512))
93 +
94 +
95 class SourceDocument(TimestampMixin, YearOwnedMixin, Base):
96 __tablename__ = "source_documents"
97 __table_args__ = (
@@ -88,6 +102,9 @@ class SourceDocument(TimestampMixin, YearOwnedMixin, Base):
102 file_hash: Mapped[str] = mapped_column(String(128))
103 document_type: Mapped[str] = mapped_column(String(64))
104 uploaded_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
105 + source_file_hash: Mapped[str | None] = mapped_column(
106 + ForeignKey("source_files.sha256", ondelete="RESTRICT"), nullable=True
107 + )
108
109
110 class AccountVersion(TimestampMixin, YearOwnedMixin, Base):
backend/src/aram_backend/services/source_store.py new
+69
@@ -0,0 +1,69 @@
1 +"""Content-addressed source-byte store on disk (D-06, booklet §5, P-01).
2 +
3 +Source bytes are immutable once written: the path is derived from the SHA-256 of
4 +the content, writes are atomic and idempotent, and reads re-verify the hash so a
5 +corrupted or tampered store fails loudly (P-09). The database keeps only
6 +metadata (SourceFile); the bytes live here, never in a DB blob.
7 +"""
8 +
9 +from __future__ import annotations
10 +
11 +import hashlib
12 +import os
13 +import tempfile
14 +from dataclasses import dataclass
15 +from pathlib import Path
16 +
17 +
18 +class SourceStoreError(ValueError):
19 + """Raised when stored bytes cannot be trusted."""
20 +
21 +
22 +@dataclass(frozen=True)
23 +class StoredFile:
24 + sha256: str
25 + size: int
26 + stored_path: str
27 +
28 +
29 +class SourceStore:
30 + """A sharded, content-addressed directory of immutable source files."""
31 +
32 + def __init__(self, root: str | Path) -> None:
33 + self.root = Path(root)
34 +
35 + def _path_for(self, sha256: str) -> Path:
36 + return self.root / sha256[:2] / sha256
37 +
38 + def put(self, content: bytes) -> StoredFile:
39 + if not content:
40 + raise SourceStoreError("source file must not be empty")
41 + digest = hashlib.sha256(content).hexdigest()
42 + target = self._path_for(digest)
43 + if target.exists():
44 + existing = target.read_bytes()
45 + if hashlib.sha256(existing).hexdigest() != digest:
46 + raise SourceStoreError("content-addressed store is corrupted")
47 + else:
48 + target.parent.mkdir(parents=True, exist_ok=True)
49 + fd, tmp = tempfile.mkstemp(dir=str(target.parent))
50 + try:
51 + with os.fdopen(fd, "wb") as handle:
52 + handle.write(content)
53 + os.replace(tmp, target)
54 + finally:
55 + if os.path.exists(tmp):
56 + os.unlink(tmp)
57 + return StoredFile(sha256=digest, size=len(content), stored_path=str(target))
58 +
59 + def get(self, sha256: str) -> bytes:
60 + target = self._path_for(sha256)
61 + if not target.exists():
62 + raise SourceStoreError(f"source file {sha256} is not in the store")
63 + content = target.read_bytes()
64 + if hashlib.sha256(content).hexdigest() != sha256:
65 + raise SourceStoreError("stored bytes do not match their hash")
66 + return content
67 +
68 +
69 +__all__ = ["SourceStore", "StoredFile", "SourceStoreError"]
backend/tests/test_ledger_csv.py new
+89
@@ -0,0 +1,89 @@
1 +"""D-06 acceptance: CSV ledger support with the same rules as XLSX."""
2 +
3 +from __future__ import annotations
4 +
5 +import pytest
6 +
7 +from aram_backend.ledger_parser import (
8 + LedgerParseError,
9 + parse_general_ledger_csv,
10 + parse_ledger,
11 +)
12 +
13 +HEADER = ["حساب", "kol", "ACCOUNT_NAME", "year", "نوع",
14 + "T1_CODE", "T2_CODE", "T3_CODE", "T4_CODE",
15 + "OPENING", "Debit", "Credit", "CLOSING"]
16 +ROW = ["0101", "14", "نمونه حساب", "۱۴۰۴", "O", "", "", "", "", "۰", "۱۲۵۰", "۰", "۱۲۵۰"]
17 +
18 +
19 +def _csv(header, row, sep=",", encoding="utf-8"):
20 + return (sep.join(header) + "\n" + sep.join(row) + "\n").encode(encoding)
21 +
22 +
23 +def test_csv_utf8_parses_with_normalization():
24 + content = _csv(HEADER, ROW)
25 + records = list(parse_general_ledger_csv(content))
26 + assert len(records) == 1
27 + r = records[0]
28 + assert r.account_code == "0101"
29 + assert r.source_year == 1404
30 + assert str(r.debit) == "1250"
31 + assert r.account_name == "نمونه حساب"
32 +
33 +
34 +def test_csv_utf8_bom():
35 + content = b"\xef\xbb\xbf" + _csv(HEADER, ROW)
36 + assert list(parse_general_ledger_csv(content))[0].account_code == "0101"
37 +
38 +
39 +def test_csv_windows_1256():
40 + # cp1256 cannot encode Persian digits; a Windows-1256 export uses ASCII numerals.
41 + row = ROW.copy()
42 + row[3] = "1404"
43 + row[9] = row[11] = row[12] = "0"
44 + row[10] = "1250"
45 + content = _csv(HEADER, row, encoding="cp1256")
46 + assert list(parse_general_ledger_csv(content))[0].debit == 1250
47 +
48 +
49 +def test_csv_tab_delimiter():
50 + content = _csv(HEADER, ROW, sep="\t")
51 + assert list(parse_general_ledger_csv(content))[0].account_code == "0101"
52 +
53 +
54 +def test_csv_semicolon_delimiter():
55 + content = _csv(HEADER, ROW, sep=";")
56 + assert list(parse_general_ledger_csv(content))[0].account_code == "0101"
57 +
58 +
59 +def test_csv_leading_zeros_preserved():
60 + row = ROW.copy()
61 + row[0] = "۰۰۱۲"
62 + content = _csv(HEADER, row)
63 + assert list(parse_general_ledger_csv(content))[0].account_code == "0012"
64 +
65 +
66 +def test_csv_missing_required_header_raises():
67 + header = [h for h in HEADER if h != "Debit"]
68 + row = ROW[:5] + ROW[6:]
69 + content = _csv(header, row)
70 + with pytest.raises(LedgerParseError, match="missing required headers"):
71 + list(parse_general_ledger_csv(content))
72 +
73 +
74 +def test_csv_empty_raises():
75 + with pytest.raises(LedgerParseError, match="empty"):
76 + list(parse_general_ledger_csv(b""))
77 +
78 +
79 +def test_parse_ledger_routes_by_extension():
80 + content = _csv(HEADER, ROW)
81 + assert list(parse_ledger(content, "ledger.csv"))[0].account_code == "0101"
82 + with pytest.raises(LedgerParseError, match="only .xlsx and .csv"):
83 + list(parse_ledger(content, "ledger.txt"))
84 +
85 +
86 +def test_csv_streaming_is_iterator():
87 + content = _csv(HEADER, ROW)
88 + result = parse_general_ledger_csv(content)
89 + assert hasattr(result, "__next__")
backend/tests/test_source_store.py new
+104
@@ -0,0 +1,104 @@
1 +"""D-06 acceptance: content-addressed source storage + hash-verified re-import."""
2 +
3 +from __future__ import annotations
4 +
5 +import hashlib
6 +import io
7 +
8 +import pytest
9 +from openpyxl import Workbook
10 +
11 +from aram_backend.ingestion import register_source_document
12 +from aram_backend.ledger_parser import parse_general_ledger, parse_ledger
13 +from aram_backend.models import Company, FiscalYear, SourceFile
14 +from aram_backend.services.source_store import SourceStore, SourceStoreError
15 +
16 +
17 +def _xlsx_bytes():
18 + wb = Workbook()
19 + ws = wb.active
20 + ws.title = "Source"
21 + ws.append(["source ledger"])
22 + ws.append(["حساب", "kol", "ACCOUNT_NAME", "year", "نوع",
23 + "T1_CODE", "T2_CODE", "T3_CODE", "T4_CODE",
24 + "OPENING", "Debit", "Credit", "CLOSING"])
25 + ws.append(["0101", "14", "نمونه", 1404, "O", None, None, None, None, 0, 100, 0, 100])
26 + buf = io.BytesIO()
27 + wb.save(buf)
28 + wb.close()
29 + return buf.getvalue()
30 +
31 +
32 +def _make_year(session):
33 + company = Company(code="SRC", name="شرکت")
34 + session.add(company)
35 + session.flush()
36 + year = FiscalYear(company_id=company.id, year=1404)
37 + session.add(year)
38 + session.flush()
39 + return year
40 +
41 +
42 +class TestSourceStore:
43 + def test_put_get_roundtrip(self, tmp_path):
44 + store = SourceStore(tmp_path / "store")
45 + content = b"immutable source bytes"
46 + stored = store.put(content)
47 + assert stored.sha256 == hashlib.sha256(content).hexdigest()
48 + assert stored.size == len(content)
49 + assert store.get(stored.sha256) == content
50 +
51 + def test_put_idempotent(self, tmp_path):
52 + store = SourceStore(tmp_path / "store")
53 + a = store.put(b"same")
54 + b = store.put(b"same")
55 + assert a.sha256 == b.sha256
56 + assert a.stored_path == b.stored_path
57 +
58 + def test_empty_rejected(self, tmp_path):
59 + with pytest.raises(SourceStoreError):
60 + SourceStore(tmp_path).put(b"")
61 +
62 + def test_corruption_detected(self, tmp_path):
63 + store = SourceStore(tmp_path / "store")
64 + stored = store.put(b"original")
65 + # Tamper with the stored bytes; the hash check must fail loudly.
66 + from pathlib import Path
67 + Path(stored.stored_path).write_bytes(b"tampered")
68 + with pytest.raises(SourceStoreError):
69 + store.get(stored.sha256)
70 +
71 + def test_missing_file_raises(self, tmp_path):
72 + with pytest.raises(SourceStoreError):
73 + SourceStore(tmp_path).get("0" * 64)
74 +
75 +
76 +class TestRegistrationWithStore:
77 + def test_bytes_persisted_and_reimport_matches_hash(self, session, tmp_path):
78 + year = _make_year(session)
79 + store = SourceStore(tmp_path / "store")
80 + content = _xlsx_bytes()
81 + source = register_source_document(
82 + session, year_id=year.id, filename="ledger.xlsx",
83 + document_type="general_ledger", content=content, store=store,
84 + )
85 + session.commit()
86 + assert source.source_file_hash == hashlib.sha256(content).hexdigest()
87 + assert not hasattr(source, "content") # metadata-only model (accepted contract)
88 + sf = session.get(SourceFile, source.source_file_hash)
89 + assert sf is not None and sf.size == len(content)
90 + # Re-import from the stored bytes: hash matches and rows parse identically.
91 + retrieved = store.get(source.source_file_hash)
92 + assert hashlib.sha256(retrieved).hexdigest() == source.file_hash
93 + original = list(parse_general_ledger(content))
94 + again = list(parse_ledger(retrieved, "ledger.xlsx"))
95 + assert again == original
96 +
97 + def test_without_store_backward_compatible(self, session):
98 + year = _make_year(session)
99 + source = register_source_document(
100 + session, year_id=year.id, filename="ledger.xlsx",
101 + document_type="general_ledger", content=_xlsx_bytes(),
102 + )
103 + session.commit()
104 + assert source.source_file_hash is None