oliver-zehentleitner / maity

clean-up: data lifecycle: duplicate constants and helpers, stale tables.py comments

Sign in to report

tsk-7wma3exmes0z Open

From the clean-up audit (tsk-hgnbapyw7hnh), area 16 (data lifecycle), read at 80647565. File and line references are at that SHA; check them against current main first. All items are low risk.

1. Duplication: the deleted-account name is defined twice

  • Files: hub/src/maity_hub/views.py:42 and account_deletion.py:57 (both DELETED_NAME = "Deleted account"); the same text as prose in help.md:613 and notifications/items.py:1117.
  • What is wrong: the name stored in the row (account_deletion) and the name shown at read time (views.deleted_person) are separate constants, so a change to one would not reach the other.
  • Proposal: account_deletion imports views.DELETED_NAME. Check that this adds no import cycle.
  • Effort: S. Risk: none.

2. Duplication: db.py writes the same do_connect hook three times

  • Files: db.py:186-188 (_hook, the serving engines), :340-342 (make_listener_engine), :368-370 (make_health_engine). Each defines the same _connect that calls connect_once_more_on_dns(dialect.loaded_dbapi.connect, cargs, cparams[, pause]).
  • Proposal: _retry_dns(engine, pause=None), called by all three engines.
  • Effort: S. Risk: low. The DNS retry test should cover it.

3. Duplication: migration helpers copied between revisions

  • Files: _json (decode a JSON column that SQLite or MariaDB returns as a string) at migrations/versions/0101_card_data_written_in_full.py:37, 0107_setup_ktw_ci_dashboard.py:32, 20261031190604_jour_fixe_series.py:62, 20261112150000_nudged_through.py:57. The same idea is written inline in 0020, 0097 and 20261108230000. _each_batch_commits (an autocommit block on MariaDB) at 20261112170000_notif_recipients.py:169 and 20261112190000_join_seq.py:100, identical apart from the docstring.
  • What is wrong: each new data migration copies these helpers. The batch-commit rule for MariaDB in particular is a convention that should live in one place.
  • Proposal: a migrations/_helpers.py (not a revision) that new migrations import. Leave the existing revisions as they are, since they are history.
  • Effort: S. Risk: low, if only new revisions use it.

4. Docs drift: tables.py comments no longer match the schema

  • tables.py:1: "the schema 0002 creates". The schema is now the head of more than 150 revisions.
  • tables.py:14-17: "whether a session is listening ... moves to the database before a second replica exists". It has moved: long_poll and hub_pod (tables.py:1128-1169) hold it on PostgreSQL, see listening.py:1-11.
  • tables.py:10-12: "No table or column is named after an SQL keyword of any of the three engines". forge_budget.limit (tables.py:1151) is reserved on PostgreSQL, MySQL/MariaDB and SQLite. card.rank (tables.py:1489) is reserved in MySQL 8.0, though not in MariaDB as far as known. SQLAlchemy quotes both, so nothing breaks today; only hand-written SQL would.
  • tables.py:2507: by_instance "null until agent instances exist (§6.17)". Instances exist, and memory.py:438 writes it for the role store.
  • Proposal: fix the four comments.
  • Effort: S. Risk: none.

Open question

Item 4: should forge_budget.limit be renamed with a small migration, or should the tables.py rule be weakened to "no hand-written SQL names them unquoted"? Either is cheap. The rename is a schema change and needs a migration on all three engines.

Notes

  1. Maity Coder Claude 003 · Nov 20, 2026, 17:04 UTC

    Audit round 3b (read at 80fef076): item 4 reserved-word bullet is fixed (hub/src/maity_hub/tables.py:10-15). Still open: the 0002 bullet (tables.py:1) and listening-not-in-a-table (tables.py:17-22) against hub_pod/long_poll at :1164-1205.