BUG-HUNT: [type-safety] Unsafe type: ignore in LegacyDataMigrator #3051

Closed
opened 2026-04-05 04:18:13 +00:00 by freemo · 3 comments
Owner

Metadata

  • Branch: fix/type-safety-legacy-migrator-type-ignore
  • Commit Message: fix(database): replace type: ignore with assert for type narrowing in LegacyDataMigrator
  • Milestone: v3.6.0
  • Parent Epic: #400

Bug Report: [type-safety] — Unsafe type: ignore in LegacyDataMigrator

Severity Assessment

  • Impact: Reduced code clarity and maintainability.
  • Likelihood: High. This is a code quality issue that is present in the current codebase.
  • Priority: Low

Location

  • File: src/cleveragents/infrastructure/database/legacy_migrator.py
  • Function/Class: LegacyDataMigrator.migrate_project_data
  • Lines: 111

Description

The migrate_project_data method uses # type: ignore to suppress a potential type error. While the code is logically correct due to the preceding if existing_plan: check, the use of type: ignore is a code smell and should be avoided in favor of more explicit type narrowing. Per project standards, # type: ignore is strictly forbidden.

Evidence

                        if existing_plan:
                            plan_id_map[plan_name] = existing_plan.id  # type: ignore
                            continue

Expected Behavior

The code should be written in a way that does not require type: ignore. An assert statement should be used to provide explicit type narrowing to the type checker.

Actual Behavior

type: ignore is used to suppress a type error, violating the project's no-type-ignore policy.

Suggested Fix

Use an assert statement to provide a type hint to the type checker:

                        if existing_plan:
                            assert existing_plan.id is not None
                            plan_id_map[plan_name] = existing_plan.id
                            continue

Category

type-safety

Subtasks

  • Remove the # type: ignore comment from line 111 of src/cleveragents/infrastructure/database/legacy_migrator.py
  • Add assert existing_plan.id is not None before the assignment to provide explicit type narrowing
  • Verify no other # type: ignore suppressions exist in legacy_migrator.py
  • Add / update BDD unit-test scenario in features/ covering the migrate_project_data method with a plan that has a non-None id
  • Verify nox -e typecheck passes with no new errors
  • Verify nox -e unit_tests passes
  • Verify nox -e coverage_report reports coverage ≥ 97%

Definition of Done

  • # type: ignore removed from LegacyDataMigrator.migrate_project_data in legacy_migrator.py
  • Explicit assert existing_plan.id is not None type narrowing added in its place
  • No new # type: ignore suppressions introduced anywhere
  • BDD scenario(s) added/updated in features/ covering the corrected code path
  • All nox stages pass (lint, typecheck, unit_tests, integration_tests, coverage_report)
  • Coverage >= 97%
  • PR merged to the correct branch with the commit message above, closing this issue

Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/type-safety-legacy-migrator-type-ignore` - **Commit Message**: `fix(database): replace type: ignore with assert for type narrowing in LegacyDataMigrator` - **Milestone**: v3.6.0 - **Parent Epic**: #400 ## Bug Report: [type-safety] — Unsafe `type: ignore` in LegacyDataMigrator ### Severity Assessment - **Impact**: Reduced code clarity and maintainability. - **Likelihood**: High. This is a code quality issue that is present in the current codebase. - **Priority**: Low ### Location - **File**: `src/cleveragents/infrastructure/database/legacy_migrator.py` - **Function/Class**: `LegacyDataMigrator.migrate_project_data` - **Lines**: 111 ### Description The `migrate_project_data` method uses `# type: ignore` to suppress a potential type error. While the code is logically correct due to the preceding `if existing_plan:` check, the use of `type: ignore` is a code smell and should be avoided in favor of more explicit type narrowing. Per project standards, `# type: ignore` is strictly forbidden. ### Evidence ```python if existing_plan: plan_id_map[plan_name] = existing_plan.id # type: ignore continue ``` ### Expected Behavior The code should be written in a way that does not require `type: ignore`. An `assert` statement should be used to provide explicit type narrowing to the type checker. ### Actual Behavior `type: ignore` is used to suppress a type error, violating the project's no-type-ignore policy. ### Suggested Fix Use an `assert` statement to provide a type hint to the type checker: ```python if existing_plan: assert existing_plan.id is not None plan_id_map[plan_name] = existing_plan.id continue ``` ### Category type-safety ## Subtasks - [ ] Remove the `# type: ignore` comment from line 111 of `src/cleveragents/infrastructure/database/legacy_migrator.py` - [ ] Add `assert existing_plan.id is not None` before the assignment to provide explicit type narrowing - [ ] Verify no other `# type: ignore` suppressions exist in `legacy_migrator.py` - [ ] Add / update BDD unit-test scenario in `features/` covering the `migrate_project_data` method with a plan that has a non-None `id` - [ ] Verify `nox -e typecheck` passes with no new errors - [ ] Verify `nox -e unit_tests` passes - [ ] Verify `nox -e coverage_report` reports coverage ≥ 97% ## Definition of Done - [ ] `# type: ignore` removed from `LegacyDataMigrator.migrate_project_data` in `legacy_migrator.py` - [ ] Explicit `assert existing_plan.id is not None` type narrowing added in its place - [ ] No new `# type: ignore` suppressions introduced anywhere - [ ] BDD scenario(s) added/updated in `features/` covering the corrected code path - [ ] All nox stages pass (`lint`, `typecheck`, `unit_tests`, `integration_tests`, `coverage_report`) - [ ] Coverage >= 97% - [ ] PR merged to the correct branch with the commit message above, closing this issue --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.6.0 milestone 2026-04-05 04:18:28 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Confirmed
  • MoSCoW: Should Have

Valid finding verified during batch triage.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Confirmed - **MoSCoW**: Should Have Valid finding verified during batch triage. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Author
Owner

Starting implementation on branch fix/type-safety-legacy-migrator-type-ignore.

Fix identified: Line 111 of legacy_migrator.py uses # type: ignore to suppress a type error on existing_plan.id. The fix is to add assert existing_plan.id is not None before the assignment, providing explicit type narrowing to the type checker.

Difficulty assessment: Low → starting at sonnet tier.


Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-issue-worker

Starting implementation on branch `fix/type-safety-legacy-migrator-type-ignore`. **Fix identified:** Line 111 of `legacy_migrator.py` uses `# type: ignore` to suppress a type error on `existing_plan.id`. The fix is to add `assert existing_plan.id is not None` before the assignment, providing explicit type narrowing to the type checker. **Difficulty assessment:** Low → starting at sonnet tier. --- **Automated by CleverAgents Bot** Supervisor: Implementation | Agent: ca-issue-worker
Author
Owner

All subtasks complete. Quality gates passed. PR #3241 created on branch fix/type-safety-legacy-migrator-type-ignore. PR review and merge handled by continuous review stream.

Implementation summary:

  • Removed # type: ignore from legacy_migrator.py line 111
  • Added assert existing_plan.id is not None for explicit type narrowing
  • Added BDD scenario covering the assert-based type narrowing path
  • nox -e lint | nox -e typecheck (0 errors) | nox -e unit_tests (26 scenarios passed)

Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-issue-worker

All subtasks complete. Quality gates passed. PR #3241 created on branch `fix/type-safety-legacy-migrator-type-ignore`. PR review and merge handled by continuous review stream. **Implementation summary:** - Removed `# type: ignore` from `legacy_migrator.py` line 111 - Added `assert existing_plan.id is not None` for explicit type narrowing - Added BDD scenario covering the assert-based type narrowing path - `nox -e lint` ✅ | `nox -e typecheck` ✅ (0 errors) | `nox -e unit_tests` ✅ (26 scenarios passed) --- **Automated by CleverAgents Bot** Supervisor: Implementation | Agent: ca-issue-worker
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
#400 Epic: Post-MVP Security
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3051
No description provided.