UAT: new_repositories.DecisionRepository uses wrong field names — will raise AttributeError at runtime when persisting decisions #3952

Open
opened 2026-04-06 07:48:30 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/decision-repository-wrong-field-names
  • Commit Message: fix(infrastructure): remove duplicate DecisionRepository with wrong field names from new_repositories
  • Milestone: Backlog (see scope guard note below)
  • Parent Epic: #394

Bug Report

Feature Area: Infrastructure and Database Layer
Severity: Critical — causes AttributeError at runtime for all decision persistence operations via new_repositories.DecisionRepository
Found by: UAT tester (code analysis)


What Was Tested

Code analysis of src/cleveragents/infrastructure/database/new_repositories.py DecisionRepository class against the DecisionModel defined in src/cleveragents/infrastructure/database/models.py.

Expected Behavior (from spec and models.py)

DecisionRepository.create() should use the correct DecisionModel column names:

  • Primary key: decision_id (String(26), ULID)
  • Plan reference: plan_id (FK to v3_plans)
  • Decision content: question, chosen_option, decision_type, sequence_number, context_snapshot_json

DecisionRepository.get() should filter by decision_id.

Actual Behavior

src/cleveragents/infrastructure/database/new_repositories.py (lines 62-101) uses wrong field names that do not exist on the DecisionModel in models.py:

# new_repositories.py lines 78-83 — WRONG field names
db_model = DecisionModel(
    id=decision.id,              # ❌ No 'id' column — should be 'decision_id'
    plan_id=decision.plan_id,    # ✓ correct
    prompt=decision.prompt,      # ❌ No 'prompt' column — should be 'question'
    decision=decision.decision,  # ❌ No 'decision' column — should be 'chosen_option'
    # Missing required fields: decision_type, sequence_number, context_snapshot_json
)

# new_repositories.py line 96 — WRONG filter field
row = session.query(DecisionModel).filter_by(id=decision_id).first()
# ❌ No 'id' column — should be filter_by(decision_id=decision_id)

The actual DecisionModel in models.py (lines 2665-2902) has:

  • decision_id (PK, String(26))
  • plan_id (FK, String(26))
  • question (Text, NOT NULL)
  • chosen_option (Text, NOT NULL)
  • decision_type (String(30), NOT NULL)
  • sequence_number (Integer, NOT NULL)
  • context_snapshot_json (Text, NOT NULL)

Steps to Reproduce

from cleveragents.infrastructure.database.new_repositories import DecisionRepository

# This will raise AttributeError: 'DecisionModel' has no attribute 'id'
# when DecisionRepository.create() is called

Code Location

  • Broken file: src/cleveragents/infrastructure/database/new_repositories.py (lines 62-101)
  • Correct model: src/cleveragents/infrastructure/database/models.py (lines 2665-2902, DecisionModel)
  • Correct repository: src/cleveragents/infrastructure/database/repositories.py (line 5126, DecisionRepository)

Root Cause

new_repositories.py was written referencing the DecisionModel from new_models.py (which has id, prompt, decision columns) but actually imports DecisionModel from models.py (which has the correct spec-aligned schema). The new_repositories.DecisionRepository is also a duplicate of the correct DecisionRepository already implemented in repositories.py.

Fix Required

Remove DecisionRepository from new_repositories.py entirely — a correct, complete implementation already exists in repositories.py (line 5126). The unit_of_work.py already imports DecisionRepository from repositories.py (line 24), so this duplicate is unused.


Subtasks

  • Verify unit_of_work.py imports DecisionRepository from repositories.py (not new_repositories.py)
  • Remove DecisionRepository class from src/cleveragents/infrastructure/database/new_repositories.py
  • Verify no other module imports DecisionRepository from new_repositories
  • Run nox -s tests to confirm no regressions
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

  • DecisionRepository removed from new_repositories.py
  • No remaining imports of DecisionRepository from new_repositories anywhere in the codebase
  • All existing DecisionRepository tests pass against the correct implementation in repositories.py
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.3.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/decision-repository-wrong-field-names` - **Commit Message**: `fix(infrastructure): remove duplicate DecisionRepository with wrong field names from new_repositories` - **Milestone**: Backlog (see scope guard note below) - **Parent Epic**: #394 ## Bug Report **Feature Area:** Infrastructure and Database Layer **Severity:** Critical — causes `AttributeError` at runtime for all decision persistence operations via `new_repositories.DecisionRepository` **Found by:** UAT tester (code analysis) --- ## What Was Tested Code analysis of `src/cleveragents/infrastructure/database/new_repositories.py` `DecisionRepository` class against the `DecisionModel` defined in `src/cleveragents/infrastructure/database/models.py`. ## Expected Behavior (from spec and models.py) `DecisionRepository.create()` should use the correct `DecisionModel` column names: - Primary key: `decision_id` (String(26), ULID) - Plan reference: `plan_id` (FK to v3_plans) - Decision content: `question`, `chosen_option`, `decision_type`, `sequence_number`, `context_snapshot_json` `DecisionRepository.get()` should filter by `decision_id`. ## Actual Behavior `src/cleveragents/infrastructure/database/new_repositories.py` (lines 62-101) uses **wrong field names** that do not exist on the `DecisionModel` in `models.py`: ```python # new_repositories.py lines 78-83 — WRONG field names db_model = DecisionModel( id=decision.id, # ❌ No 'id' column — should be 'decision_id' plan_id=decision.plan_id, # ✓ correct prompt=decision.prompt, # ❌ No 'prompt' column — should be 'question' decision=decision.decision, # ❌ No 'decision' column — should be 'chosen_option' # Missing required fields: decision_type, sequence_number, context_snapshot_json ) # new_repositories.py line 96 — WRONG filter field row = session.query(DecisionModel).filter_by(id=decision_id).first() # ❌ No 'id' column — should be filter_by(decision_id=decision_id) ``` The actual `DecisionModel` in `models.py` (lines 2665-2902) has: - `decision_id` (PK, String(26)) - `plan_id` (FK, String(26)) - `question` (Text, NOT NULL) - `chosen_option` (Text, NOT NULL) - `decision_type` (String(30), NOT NULL) - `sequence_number` (Integer, NOT NULL) - `context_snapshot_json` (Text, NOT NULL) ## Steps to Reproduce ```python from cleveragents.infrastructure.database.new_repositories import DecisionRepository # This will raise AttributeError: 'DecisionModel' has no attribute 'id' # when DecisionRepository.create() is called ``` ## Code Location - **Broken file:** `src/cleveragents/infrastructure/database/new_repositories.py` (lines 62-101) - **Correct model:** `src/cleveragents/infrastructure/database/models.py` (lines 2665-2902, `DecisionModel`) - **Correct repository:** `src/cleveragents/infrastructure/database/repositories.py` (line 5126, `DecisionRepository`) ## Root Cause `new_repositories.py` was written referencing the `DecisionModel` from `new_models.py` (which has `id`, `prompt`, `decision` columns) but actually imports `DecisionModel` from `models.py` (which has the correct spec-aligned schema). The `new_repositories.DecisionRepository` is also a duplicate of the correct `DecisionRepository` already implemented in `repositories.py`. ## Fix Required Remove `DecisionRepository` from `new_repositories.py` entirely — a correct, complete implementation already exists in `repositories.py` (line 5126). The `unit_of_work.py` already imports `DecisionRepository` from `repositories.py` (line 24), so this duplicate is unused. --- ## Subtasks - [ ] Verify `unit_of_work.py` imports `DecisionRepository` from `repositories.py` (not `new_repositories.py`) - [ ] Remove `DecisionRepository` class from `src/cleveragents/infrastructure/database/new_repositories.py` - [ ] Verify no other module imports `DecisionRepository` from `new_repositories` - [ ] Run `nox -s tests` to confirm no regressions - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done - [ ] `DecisionRepository` removed from `new_repositories.py` - [ ] No remaining imports of `DecisionRepository` from `new_repositories` anywhere in the codebase - [ ] All existing `DecisionRepository` tests pass against the correct implementation in `repositories.py` - [ ] A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly - [ ] The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly - [ ] The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done - All nox stages pass - Coverage >= 97% --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.3.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#394 Epic: Decision Framework
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3952
No description provided.