[Debt] Define shared SQLAlchemy change-tracking helpers for modules #252

Closed
opened 2026-07-13 17:21:11 +02:00 by zemion · 1 comment
Owner

Created from add-ideas/govoplan#3 after triaging /mnt/DATA/git/govoplan/audit-reports/govoplan-full-20260711-1857/jscpd/jscpd-report.json.

Evidence

jscpd reports duplicated SQLAlchemy change-tracking helpers across modules:

  • govoplan_campaign/backend/change_tracking.py lines 295-322
  • govoplan_files/backend/change_tracking.py lines 151-178

The duplicated helpers inspect pending/deleted state, changed attributes, previous values, ID assignment, and operation classification. Drift here can change audit/event behavior across modules.

Desired Shape

Move only generic SQLAlchemy state inspection helpers into a core utility. Keep domain-specific payload construction and event semantics in the owning modules.

Acceptance Criteria

  • Shared helpers cover generic state inspection and previous-value extraction.
  • Campaign/files keep module-specific payload/event construction locally.
  • Existing change tracking tests pass or are added where missing.
  • The cross-module helper clone is removed or explicitly documented as intentionally divergent.
Created from add-ideas/govoplan#3 after triaging `/mnt/DATA/git/govoplan/audit-reports/govoplan-full-20260711-1857/jscpd/jscpd-report.json`. ## Evidence jscpd reports duplicated SQLAlchemy change-tracking helpers across modules: - `govoplan_campaign/backend/change_tracking.py` lines 295-322 - `govoplan_files/backend/change_tracking.py` lines 151-178 The duplicated helpers inspect pending/deleted state, changed attributes, previous values, ID assignment, and operation classification. Drift here can change audit/event behavior across modules. ## Desired Shape Move only generic SQLAlchemy state inspection helpers into a core utility. Keep domain-specific payload construction and event semantics in the owning modules. ## Acceptance Criteria - Shared helpers cover generic state inspection and previous-value extraction. - Campaign/files keep module-specific payload/event construction locally. - Existing change tracking tests pass or are added where missing. - The cross-module helper clone is removed or explicitly documented as intentionally divergent.
Author
Owner

Codex State: done

Summary

  • Added shared core SQLAlchemy change-tracking helpers for object state, changed attributes, previous values, ID assignment, generic operation, and soft-delete operation classification.
  • Updated campaign/files change tracking to use shared helpers while keeping domain payload/event construction local.

Changed Files

  • src/govoplan_core/core/sqlalchemy_change_tracking.py
  • tests/test_sqlalchemy_change_tracking.py
  • ../govoplan-campaign/src/govoplan_campaign/backend/change_tracking.py
  • ../govoplan-files/src/govoplan_files/backend/change_tracking.py

Verification

  • python -m py_compile: core helper plus campaign/files change tracking passed
  • python -m unittest tests.test_sqlalchemy_change_tracking: 3 passed
  • python -m unittest discover -s tests (govoplan-files): 14 passed
  • python -m unittest discover -s tests (govoplan-campaign): 2 passed
  • npx --yes jscpd --absolute --min-tokens 80 over core/campaign/files change tracking: Found 0 clones
  • python -m ruff check touched core/campaign/files/calendar files: passed
  • git diff --check in core/campaign/files/calendar: passed
## Codex State: done ### Summary - Added shared core SQLAlchemy change-tracking helpers for object state, changed attributes, previous values, ID assignment, generic operation, and soft-delete operation classification. - Updated campaign/files change tracking to use shared helpers while keeping domain payload/event construction local. ### Changed Files - `src/govoplan_core/core/sqlalchemy_change_tracking.py` - `tests/test_sqlalchemy_change_tracking.py` - `../govoplan-campaign/src/govoplan_campaign/backend/change_tracking.py` - `../govoplan-files/src/govoplan_files/backend/change_tracking.py` ### Verification - `python -m py_compile: core helper plus campaign/files change tracking passed` - `python -m unittest tests.test_sqlalchemy_change_tracking: 3 passed` - `python -m unittest discover -s tests (govoplan-files): 14 passed` - `python -m unittest discover -s tests (govoplan-campaign): 2 passed` - `npx --yes jscpd --absolute --min-tokens 80 over core/campaign/files change tracking: Found 0 clones` - `python -m ruff check touched core/campaign/files/calendar files: passed` - `git diff --check in core/campaign/files/calendar: passed`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: add-ideas/govoplan-core#252
No description provided.