UAT: new_repositories.ResourceRepository uses wrong field names — will raise AttributeError at runtime when creating or querying resources #3957

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

Metadata

  • Branch: fix/resource-repository-wrong-field-names
  • Commit Message: fix(db): correct ResourceModel field names in new_repositories.py ResourceRepository
  • Milestone: (none — backlog)
  • Parent Epic: #946

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.


Bug Report

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


What Was Tested

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

Expected Behavior (from spec and models.py)

ResourceRepository.create() should use the correct ResourceModel column names:

  • Primary key: resource_id (String(26), ULID)
  • Name: namespaced_name
  • Type: type_name
  • Classification: resource_kind
  • Properties: properties_json

ResourceRepository.get() should filter by resource_id.

Actual Behavior

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

# new_repositories.py lines 36-41 — WRONG field names
db_model = ResourceModel(
    id=resource.id,                    # No 'id' column — should be 'resource_id'
    name=resource.name,                # No 'name' column — should be 'namespaced_name'
    resource_type=resource.resource_type,  # No 'resource_type' — should be 'type_name'
    config=resource.config,            # No 'config' column — should be 'properties_json'
)

# new_repositories.py line 54 — WRONG filter field
row = session.query(ResourceModel).filter_by(id=resource_id).first()
# No 'id' column — should be filter_by(resource_id=resource_id)

The actual ResourceModel in models.py (lines 1532-1613) has:

  • resource_id (PK, String(26))
  • namespaced_name (String(255), nullable, unique)
  • type_name (FK to resource_types.name)
  • resource_kind (String(20), physical|virtual)
  • properties_json (Text, nullable)

Steps to Reproduce

from cleveragents.infrastructure.database.unit_of_work import UnitOfWork

uow = UnitOfWork("sqlite:///:memory:")
uow.init_database()

with uow.transaction() as ctx:
    # This will raise AttributeError: 'ResourceModel' has no attribute 'id'
    ctx.resources.create(some_resource)

Code Location

  • Broken file: src/cleveragents/infrastructure/database/new_repositories.py (lines 36-58)
  • Correct model: src/cleveragents/infrastructure/database/models.py (lines 1532-1613, ResourceModel)

Root Cause

new_repositories.py was written referencing the ResourceModel from new_models.py (which has id, name, resource_type, config columns) but actually imports ResourceModel from models.py (which has the correct spec-aligned schema with resource_id, namespaced_name, type_name, resource_kind, properties_json).

Fix Required

Update new_repositories.py ResourceRepository.create() to use the correct field names matching models.py's ResourceModel, or remove new_repositories.py entirely and use the existing ResourceRepository in repositories.py (which correctly uses resource_id, namespaced_name, type_name, etc.).


Subtasks

  • Audit all other repository classes in new_repositories.py for similar field-name mismatches against models.py
  • Fix ResourceRepository.create() to use resource_id, namespaced_name, type_name, resource_kind, properties_json
  • Fix ResourceRepository.get() to filter by resource_id instead of id
  • Alternatively: evaluate removing new_repositories.py entirely and routing all callers to repositories.py
  • Add or update unit tests covering ResourceRepository.create() and ResourceRepository.get() with the correct field names
  • Run nox (all default sessions), fix any errors
  • Verify coverage >= 97% via nox -s coverage_report

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off
  • ResourceRepository.create() and ResourceRepository.get() use the correct ResourceModel field names from models.py
  • No AttributeError is raised when creating or querying resources via new_repositories.py
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details
  • 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%

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

## Metadata - **Branch**: `fix/resource-repository-wrong-field-names` - **Commit Message**: `fix(db): correct ResourceModel field names in new_repositories.py ResourceRepository` - **Milestone**: *(none — backlog)* - **Parent Epic**: #946 > **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. --- ## Bug Report **Feature Area:** Infrastructure and Database Layer **Severity:** Critical — causes `AttributeError` at runtime for all resource persistence operations **Found by:** UAT tester (code analysis) --- ## What Was Tested Code analysis of `src/cleveragents/infrastructure/database/new_repositories.py` against the `ResourceModel` defined in `src/cleveragents/infrastructure/database/models.py`. ## Expected Behavior (from spec and models.py) `ResourceRepository.create()` should use the correct `ResourceModel` column names: - Primary key: `resource_id` (String(26), ULID) - Name: `namespaced_name` - Type: `type_name` - Classification: `resource_kind` - Properties: `properties_json` `ResourceRepository.get()` should filter by `resource_id`. ## Actual Behavior `src/cleveragents/infrastructure/database/new_repositories.py` (lines 36-58) uses **wrong field names** that do not exist on the `ResourceModel` in `models.py`: ```python # new_repositories.py lines 36-41 — WRONG field names db_model = ResourceModel( id=resource.id, # No 'id' column — should be 'resource_id' name=resource.name, # No 'name' column — should be 'namespaced_name' resource_type=resource.resource_type, # No 'resource_type' — should be 'type_name' config=resource.config, # No 'config' column — should be 'properties_json' ) # new_repositories.py line 54 — WRONG filter field row = session.query(ResourceModel).filter_by(id=resource_id).first() # No 'id' column — should be filter_by(resource_id=resource_id) ``` The actual `ResourceModel` in `models.py` (lines 1532-1613) has: - `resource_id` (PK, String(26)) - `namespaced_name` (String(255), nullable, unique) - `type_name` (FK to resource_types.name) - `resource_kind` (String(20), physical|virtual) - `properties_json` (Text, nullable) ## Steps to Reproduce ```python from cleveragents.infrastructure.database.unit_of_work import UnitOfWork uow = UnitOfWork("sqlite:///:memory:") uow.init_database() with uow.transaction() as ctx: # This will raise AttributeError: 'ResourceModel' has no attribute 'id' ctx.resources.create(some_resource) ``` ## Code Location - **Broken file:** `src/cleveragents/infrastructure/database/new_repositories.py` (lines 36-58) - **Correct model:** `src/cleveragents/infrastructure/database/models.py` (lines 1532-1613, `ResourceModel`) ## Root Cause `new_repositories.py` was written referencing the `ResourceModel` from `new_models.py` (which has `id`, `name`, `resource_type`, `config` columns) but actually imports `ResourceModel` from `models.py` (which has the correct spec-aligned schema with `resource_id`, `namespaced_name`, `type_name`, `resource_kind`, `properties_json`). ## Fix Required Update `new_repositories.py` `ResourceRepository.create()` to use the correct field names matching `models.py`'s `ResourceModel`, or remove `new_repositories.py` entirely and use the existing `ResourceRepository` in `repositories.py` (which correctly uses `resource_id`, `namespaced_name`, `type_name`, etc.). --- ## Subtasks - [ ] Audit all other repository classes in `new_repositories.py` for similar field-name mismatches against `models.py` - [ ] Fix `ResourceRepository.create()` to use `resource_id`, `namespaced_name`, `type_name`, `resource_kind`, `properties_json` - [ ] Fix `ResourceRepository.get()` to filter by `resource_id` instead of `id` - [ ] Alternatively: evaluate removing `new_repositories.py` entirely and routing all callers to `repositories.py` - [ ] Add or update unit tests covering `ResourceRepository.create()` and `ResourceRepository.get()` with the correct field names - [ ] Run `nox` (all default sessions), fix any errors - [ ] Verify coverage >= 97% via `nox -s coverage_report` ## Definition of Done This issue is complete when: - [ ] All subtasks above are completed and checked off - [ ] `ResourceRepository.create()` and `ResourceRepository.get()` use the correct `ResourceModel` field names from `models.py` - [ ] No `AttributeError` is raised when creating or querying resources via `new_repositories.py` - [ ] A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details - [ ] 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% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Author
Owner

⚠️ Duplicate — This issue is a duplicate of #3954 (same title and content). Closing as duplicate.


Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: ca-backlog-groomer

⚠️ **Duplicate** — This issue is a duplicate of #3954 (same title and content). Closing as duplicate. --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: ca-backlog-groomer
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#3957
No description provided.