UAT: new_models.py defines orphaned duplicate ORM models with a separate Base — creates confusion and potential SQLAlchemy metadata conflicts #3961

Open
opened 2026-04-06 07:53:50 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/db-remove-orphaned-new-models
  • Commit Message: chore(db): remove orphaned duplicate ORM models in new_models.py
  • Milestone: (none — backlog)
  • Parent Epic: (to be linked — see orphan note below)

Subtasks

  • Confirm new_models.py is not imported anywhere in the codebase
  • Delete src/cleveragents/infrastructure/database/new_models.py
  • Run nox -e lint and nox -e typecheck to confirm no regressions
  • Run nox -e unit_tests and nox -e integration_tests to confirm no regressions
  • Run nox -e coverage_report to confirm coverage >= 97%

Definition of Done

  • All subtasks above are checked
  • new_models.py no longer exists in the repository
  • No import of new_models exists anywhere in the codebase
  • Commit created with message: chore(db): remove orphaned duplicate ORM models in new_models.py
  • Branch pushed and PR merged
  • All nox stages pass
  • Coverage >= 97%

Bug Report

Feature Area: Infrastructure and Database Layer
Severity: Medium — orphaned code creates confusion, maintenance risk, and potential SQLAlchemy metadata conflicts
Found by: UAT tester (code analysis)


What Was Tested

Code analysis of src/cleveragents/infrastructure/database/new_models.py against src/cleveragents/infrastructure/database/models.py.

Problem

new_models.py defines 4 ORM model classes that:

  1. Use the same table names as models already defined in models.py
  2. Use a different Base (a separate declarative_base() instance)
  3. Are never imported anywhere in the codebase (confirmed by grep)
  4. Have incompatible schemas compared to the canonical models in models.py

Duplicate Models in new_models.py

Class Table Name Also in models.py? Schema Compatible?
ResourceModel resources ✓ Yes (line 1532) No — different columns
ResourceEdgeModel resource_edges ✓ Yes (line 1616) No — missing link_type, auto_discovered, created_at
DecisionModel decisions ✓ Yes (line 2665) No — uses prompt/decision instead of question/chosen_option
DecisionDependencyModel decision_dependencies ✓ Yes (line 2905) No — different column names

Schema Differences

new_models.ResourceModel (wrong):

id = Column(String(26), primary_key=True)  # should be resource_id
name = Column(String(255), nullable=False, unique=True)  # should be namespaced_name
resource_type = Column(String(255), nullable=False)  # should be type_name
config = Column(JSON, nullable=False, default=dict)  # should be properties_json

models.ResourceModel (correct, spec-aligned):

resource_id = Column(String(26), primary_key=True)
namespaced_name = Column(String(255), nullable=True, unique=True)
type_name = Column(String(255), ForeignKey("resource_types.name"))
resource_kind = Column(String(20), nullable=False)  # physical|virtual
properties_json = Column(Text, nullable=True)
# ... plus 8 more columns

Risk

If new_models.py is ever imported (e.g., by a developer following the naming pattern), SQLAlchemy will have two different Base registries mapping to the same table names. This can cause:

  • InvalidRequestError: Table 'resources' is already defined for this MetaData instance
  • Silent data corruption if the wrong model is used for queries
  • Migration confusion (Alembic only tracks one Base)

Code Location

  • Orphaned file: src/cleveragents/infrastructure/database/new_models.py (105 lines)
  • Canonical models: src/cleveragents/infrastructure/database/models.py

Fix Required

Delete src/cleveragents/infrastructure/database/new_models.py entirely. All required models already exist in models.py with the correct spec-aligned schema. The file was likely a draft that was superseded by the canonical models but never cleaned up.


Backlog note: This issue was discovered during autonomous operation
on milestone v3.6.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/db-remove-orphaned-new-models` - **Commit Message**: `chore(db): remove orphaned duplicate ORM models in new_models.py` - **Milestone**: *(none — backlog)* - **Parent Epic**: *(to be linked — see orphan note below)* ## Subtasks - [ ] Confirm `new_models.py` is not imported anywhere in the codebase - [ ] Delete `src/cleveragents/infrastructure/database/new_models.py` - [ ] Run `nox -e lint` and `nox -e typecheck` to confirm no regressions - [ ] Run `nox -e unit_tests` and `nox -e integration_tests` to confirm no regressions - [ ] Run `nox -e coverage_report` to confirm coverage >= 97% ## Definition of Done - [ ] All subtasks above are checked - [ ] `new_models.py` no longer exists in the repository - [ ] No import of `new_models` exists anywhere in the codebase - [ ] Commit created with message: `chore(db): remove orphaned duplicate ORM models in new_models.py` - [ ] Branch pushed and PR merged - [ ] All nox stages pass - [ ] Coverage >= 97% --- ## Bug Report **Feature Area:** Infrastructure and Database Layer **Severity:** Medium — orphaned code creates confusion, maintenance risk, and potential SQLAlchemy metadata conflicts **Found by:** UAT tester (code analysis) --- ## What Was Tested Code analysis of `src/cleveragents/infrastructure/database/new_models.py` against `src/cleveragents/infrastructure/database/models.py`. ## Problem `new_models.py` defines 4 ORM model classes that: 1. Use the **same table names** as models already defined in `models.py` 2. Use a **different `Base`** (a separate `declarative_base()` instance) 3. Are **never imported anywhere** in the codebase (confirmed by grep) 4. Have **incompatible schemas** compared to the canonical models in `models.py` ### Duplicate Models in `new_models.py` | Class | Table Name | Also in `models.py`? | Schema Compatible? | |-------|-----------|---------------------|-------------------| | `ResourceModel` | `resources` | ✓ Yes (line 1532) | ❌ No — different columns | | `ResourceEdgeModel` | `resource_edges` | ✓ Yes (line 1616) | ❌ No — missing `link_type`, `auto_discovered`, `created_at` | | `DecisionModel` | `decisions` | ✓ Yes (line 2665) | ❌ No — uses `prompt`/`decision` instead of `question`/`chosen_option` | | `DecisionDependencyModel` | `decision_dependencies` | ✓ Yes (line 2905) | ❌ No — different column names | ### Schema Differences **`new_models.ResourceModel`** (wrong): ```python id = Column(String(26), primary_key=True) # should be resource_id name = Column(String(255), nullable=False, unique=True) # should be namespaced_name resource_type = Column(String(255), nullable=False) # should be type_name config = Column(JSON, nullable=False, default=dict) # should be properties_json ``` **`models.ResourceModel`** (correct, spec-aligned): ```python resource_id = Column(String(26), primary_key=True) namespaced_name = Column(String(255), nullable=True, unique=True) type_name = Column(String(255), ForeignKey("resource_types.name")) resource_kind = Column(String(20), nullable=False) # physical|virtual properties_json = Column(Text, nullable=True) # ... plus 8 more columns ``` ## Risk If `new_models.py` is ever imported (e.g., by a developer following the naming pattern), SQLAlchemy will have **two different `Base` registries** mapping to the same table names. This can cause: - `InvalidRequestError: Table 'resources' is already defined for this MetaData instance` - Silent data corruption if the wrong model is used for queries - Migration confusion (Alembic only tracks one Base) ## Code Location - **Orphaned file:** `src/cleveragents/infrastructure/database/new_models.py` (105 lines) - **Canonical models:** `src/cleveragents/infrastructure/database/models.py` ## Fix Required Delete `src/cleveragents/infrastructure/database/new_models.py` entirely. All required models already exist in `models.py` with the correct spec-aligned schema. The file was likely a draft that was superseded by the canonical models but never cleaned up. --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.6.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
Author
Owner

⚠️ Orphan Issue — Manual Linking Required

This issue was created without a parent Epic reference. Per CONTRIBUTING.md, all issues (except Epics and Legendaries) must be linked to a parent Epic using Forgejo's dependency system (child blocks parent).

A human reviewer should:

  1. Identify the appropriate parent Epic for this database/infrastructure cleanup work
  2. Create the dependency link: this issue (#3961) blocks the parent Epic

Suggested Epic candidates: any Epic covering infrastructure, database layer cleanup, or technical debt in the ORM/persistence layer.


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

⚠️ **Orphan Issue — Manual Linking Required** This issue was created without a parent Epic reference. Per CONTRIBUTING.md, all issues (except Epics and Legendaries) must be linked to a parent Epic using Forgejo's dependency system (child **blocks** parent). A human reviewer should: 1. Identify the appropriate parent Epic for this database/infrastructure cleanup work 2. Create the dependency link: this issue (#3961) **blocks** the parent Epic Suggested Epic candidates: any Epic covering infrastructure, database layer cleanup, or technical debt in the ORM/persistence layer. --- **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.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#3961
No description provided.