BUG-HUNT: [consistency] Inconsistent Boolean Default in Alembic Migrations #7868

Open
opened 2026-04-12 05:45:24 +00:00 by HAL9000 · 4 comments
Owner

Metadata

  • Branch: bugfix/backlog-alembic-boolean-defaults
  • Commit Message: fix(migrations): use sa.false() for boolean column server defaults in alembic migrations
  • Milestone: Backlog (no milestone assigned)
  • Parent Epic: TBD — see orphan note below

Background and Context

Several Alembic migration files define boolean columns using server_default="0" or server_default=sa.text("0"). While this works on SQLite, it is not portable across all database backends supported by SQLAlchemy. Some backends (e.g., PostgreSQL, MySQL) may reject a string literal "0" as a valid default for a BOOLEAN typed column, causing migration failures when deploying to those systems. SQLAlchemy provides sa.false() as the canonical, database-agnostic way to express a boolean false default.

Current Behavior

The following migration files use non-portable boolean defaults:

  • alembic/versions/4b518923afb2_add_debug_attempts_table.py (line 29): server_default="0"
  • alembic/versions/c3d9b3d0cf3e_add_actors_table.py (lines 43, 49, 55): server_default=sa.text("0")
  • alembic/versions/a5_001_add_actions_v3_table.py (lines 70, 76): server_default=sa.text("0")
  • alembic/versions/a5_002_add_lifecycle_plans_table.py (lines 114, 120): server_default=sa.text("0")
  • alembic/versions/a5_003_spec_aligned_actions.py (lines 70, 76): server_default=sa.text("0")

Example:

# From 4b518923afb2_add_debug_attempts_table.py
sa.Column("success", sa.Boolean(), nullable=False, server_default="0"),

# From c3d9b3d0cf3e_add_actors_table.py
sa.Column(
    "unsafe",
    sa.Boolean(),
    nullable=False,
    server_default=sa.text("0"),
),

Expected Behavior

All boolean columns with a false default should use server_default=sa.false(), which SQLAlchemy translates to the correct backend-specific expression (e.g., FALSE on PostgreSQL, 0 on SQLite).

# Correct portable form
sa.Column("success", sa.Boolean(), nullable=False, server_default=sa.false()),

Acceptance Criteria

  • All boolean columns in the affected migration files use server_default=sa.false() instead of server_default="0" or server_default=sa.text("0")
  • No other migration files introduce new non-portable boolean defaults
  • Migrations apply cleanly on SQLite (existing CI backend)
  • A TDD test (tagged @tdd_issue, @tdd_issue_<N>, @tdd_expected_fail) is merged before this fix is applied

Supporting Information

Subtasks

  • Create TDD issue (Type/Testing) with failing test tagged @tdd_issue, @tdd_issue_<N>, @tdd_expected_fail
  • Wait for TDD issue to be merged (this issue depends on TDD issue)
  • Replace server_default="0" with server_default=sa.false() in 4b518923afb2_add_debug_attempts_table.py
  • Replace server_default=sa.text("0") with server_default=sa.false() in c3d9b3d0cf3e_add_actors_table.py
  • Replace server_default=sa.text("0") with server_default=sa.false() in a5_001_add_actions_v3_table.py
  • Replace server_default=sa.text("0") with server_default=sa.false() in a5_002_add_lifecycle_plans_table.py
  • Replace server_default=sa.text("0") with server_default=sa.false() in a5_003_spec_aligned_actions.py
  • Remove @tdd_expected_fail tag from TDD test scenarios (keep @tdd_issue and @tdd_issue_<N>)
  • 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.
  • 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 about the implementation.
  • 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 Cycle 1 (Bug Detection). It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue must be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it. This bug issue depends on (is blocked by) the TDD issue.


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

## Metadata - **Branch**: `bugfix/backlog-alembic-boolean-defaults` - **Commit Message**: `fix(migrations): use sa.false() for boolean column server defaults in alembic migrations` - **Milestone**: Backlog (no milestone assigned) - **Parent Epic**: TBD — see orphan note below ## Background and Context Several Alembic migration files define boolean columns using `server_default="0"` or `server_default=sa.text("0")`. While this works on SQLite, it is not portable across all database backends supported by SQLAlchemy. Some backends (e.g., PostgreSQL, MySQL) may reject a string literal `"0"` as a valid default for a `BOOLEAN` typed column, causing migration failures when deploying to those systems. SQLAlchemy provides `sa.false()` as the canonical, database-agnostic way to express a boolean false default. ## Current Behavior The following migration files use non-portable boolean defaults: - `alembic/versions/4b518923afb2_add_debug_attempts_table.py` (line 29): `server_default="0"` - `alembic/versions/c3d9b3d0cf3e_add_actors_table.py` (lines 43, 49, 55): `server_default=sa.text("0")` - `alembic/versions/a5_001_add_actions_v3_table.py` (lines 70, 76): `server_default=sa.text("0")` - `alembic/versions/a5_002_add_lifecycle_plans_table.py` (lines 114, 120): `server_default=sa.text("0")` - `alembic/versions/a5_003_spec_aligned_actions.py` (lines 70, 76): `server_default=sa.text("0")` Example: ```python # From 4b518923afb2_add_debug_attempts_table.py sa.Column("success", sa.Boolean(), nullable=False, server_default="0"), # From c3d9b3d0cf3e_add_actors_table.py sa.Column( "unsafe", sa.Boolean(), nullable=False, server_default=sa.text("0"), ), ``` ## Expected Behavior All boolean columns with a false default should use `server_default=sa.false()`, which SQLAlchemy translates to the correct backend-specific expression (e.g., `FALSE` on PostgreSQL, `0` on SQLite). ```python # Correct portable form sa.Column("success", sa.Boolean(), nullable=False, server_default=sa.false()), ``` ## Acceptance Criteria - [ ] All boolean columns in the affected migration files use `server_default=sa.false()` instead of `server_default="0"` or `server_default=sa.text("0")` - [ ] No other migration files introduce new non-portable boolean defaults - [ ] Migrations apply cleanly on SQLite (existing CI backend) - [ ] A TDD test (tagged `@tdd_issue`, `@tdd_issue_<N>`, `@tdd_expected_fail`) is merged before this fix is applied ## Supporting Information - Affected files: 5 migration files across `alembic/versions/` - SQLAlchemy docs: `sa.false()` is the portable false literal — https://docs.sqlalchemy.org/en/20/core/sqlelement.html#sqlalchemy.sql.expression.false - This bug was discovered during automated bug-hunting (Cycle 1) ## Subtasks - [ ] Create TDD issue (`Type/Testing`) with failing test tagged `@tdd_issue`, `@tdd_issue_<N>`, `@tdd_expected_fail` - [ ] Wait for TDD issue to be merged (this issue depends on TDD issue) - [ ] Replace `server_default="0"` with `server_default=sa.false()` in `4b518923afb2_add_debug_attempts_table.py` - [ ] Replace `server_default=sa.text("0")` with `server_default=sa.false()` in `c3d9b3d0cf3e_add_actors_table.py` - [ ] Replace `server_default=sa.text("0")` with `server_default=sa.false()` in `a5_001_add_actions_v3_table.py` - [ ] Replace `server_default=sa.text("0")` with `server_default=sa.false()` in `a5_002_add_lifecycle_plans_table.py` - [ ] Replace `server_default=sa.text("0")` with `server_default=sa.false()` in `a5_003_spec_aligned_actions.py` - [ ] Remove `@tdd_expected_fail` tag from TDD test scenarios (keep `@tdd_issue` and `@tdd_issue_<N>`) - [ ] 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. - 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 about the implementation. - 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 Cycle 1 (Bug Detection). It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ### TDD Note After this bug issue is verified, a corresponding `Type/Testing` issue must be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. This bug issue **depends on** (is blocked by) the TDD issue. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
Author
Owner

⚠️ Orphan Issue — Needs Manual Parent Epic Linking

This issue was created by the automated bug-hunter and does not currently have a parent Epic linked via Forgejo's dependency system.

Required action: A project owner or maintainer must:

  1. Identify or create an appropriate parent Epic for Alembic migration quality/consistency issues
  2. Link this issue as a child of that Epic using Forgejo's dependency system (this issue blocks the parent Epic)

Per CONTRIBUTING.md: "Orphan issues are NOT permitted — every issue must belong to at least one Epic."


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

## ⚠️ Orphan Issue — Needs Manual Parent Epic Linking This issue was created by the automated bug-hunter and does not currently have a parent Epic linked via Forgejo's dependency system. **Required action:** A project owner or maintainer must: 1. Identify or create an appropriate parent Epic for Alembic migration quality/consistency issues 2. Link this issue as a child of that Epic using Forgejo's dependency system (this issue **blocks** the parent Epic) Per `CONTRIBUTING.md`: *"Orphan issues are NOT permitted — every issue must belong to at least one Epic."* --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
Author
Owner

Verified — Consistency bug: inconsistent boolean default in Alembic migrations. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Consistency bug: inconsistent boolean default in Alembic migrations. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Consistency bug: inconsistent boolean default in Alembic migrations. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Consistency bug: inconsistent boolean default in Alembic migrations. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Consistency bug: inconsistent boolean default in Alembic migrations. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Consistency bug: inconsistent boolean default in Alembic migrations. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#7868
No description provided.