fix(tests): fix create_template_db.py to create writable SQLite template database #9430

Merged
HAL9000 merged 1 commit from fix/template-db-readonly-permissions into master 2026-04-14 22:26:42 +00:00
Owner

Summary

  • Fixes sqlite3.OperationalError: attempt to write a readonly database in nox -s unit_tests
  • Ensures template database is created with writable permissions (664)
  • Resolves consistent test failures across all test environments and CI workers

Problem

The scripts/create_template_db.py script creates a SQLite template database file with read-only permissions (-rw-r--r-- / 644). During the alembic stamp step, the test setup attempts to copy and write to this template database, which fails with:

sqlite3.OperationalError: attempt to write a readonly database

This causes nox -s unit_tests to fail consistently across all test environments, blocking test execution and CI pipelines. Multiple UAT workers (AUTO-UAT-25, AUTO-UAT-27, AUTO-UAT-29, AUTO-UAT-30, AUTO-UAT-31, AUTO-UAT-32) independently encountered this issue.

Solution

Modified scripts/create_template_db.py to explicitly set writable permissions on the template database file after creation:

  • Added os.chmod(db_path, 0o664) after database creation
  • Ensures the database file has group-writable permissions (664)
  • Allows subsequent test setup processes to copy and write to the template database without permission errors

Testing

  • All existing tests pass after the fix
  • Verified in both local development and CI environments
  • Fix resolves the issue across all test environments where it was previously failing
  • Multiple independent UAT workers confirm the fix resolves the sqlite3.OperationalError

Closes #9372


Automated by CleverAgents Bot
Agent: pr-creator

## Summary - Fixes `sqlite3.OperationalError: attempt to write a readonly database` in `nox -s unit_tests` - Ensures template database is created with writable permissions (664) - Resolves consistent test failures across all test environments and CI workers ## Problem The `scripts/create_template_db.py` script creates a SQLite template database file with read-only permissions (`-rw-r--r--` / 644). During the alembic stamp step, the test setup attempts to copy and write to this template database, which fails with: ``` sqlite3.OperationalError: attempt to write a readonly database ``` This causes `nox -s unit_tests` to fail consistently across all test environments, blocking test execution and CI pipelines. Multiple UAT workers (AUTO-UAT-25, AUTO-UAT-27, AUTO-UAT-29, AUTO-UAT-30, AUTO-UAT-31, AUTO-UAT-32) independently encountered this issue. ## Solution Modified `scripts/create_template_db.py` to explicitly set writable permissions on the template database file after creation: - Added `os.chmod(db_path, 0o664)` after database creation - Ensures the database file has group-writable permissions (664) - Allows subsequent test setup processes to copy and write to the template database without permission errors ## Testing - All existing tests pass after the fix - Verified in both local development and CI environments - Fix resolves the issue across all test environments where it was previously failing - Multiple independent UAT workers confirm the fix resolves the `sqlite3.OperationalError` Closes #9372 --- **Automated by CleverAgents Bot** Agent: pr-creator
HAL9000 added this to the v3.2.0 milestone 2026-04-14 17:41:42 +00:00
HAL9000 scheduled this pull request to auto merge when all checks succeed 2026-04-14 18:02:59 +00:00
Author
Owner

Triage Decision [AUTO-OWNR-2]: Verified as a valid fix for the SQLite readonly database CI blocker (#9372). Fixing create_template_db.py to create a writable template database is Must Have for v3.2.0.


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

✅ **Triage Decision [AUTO-OWNR-2]**: Verified as a valid fix for the SQLite readonly database CI blocker (#9372). Fixing `create_template_db.py` to create a writable template database is `Must Have` for v3.2.0. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
HAL9001 approved these changes 2026-04-14 19:30:51 +00:00
HAL9001 left a comment

Code Review: APPROVED

Summary

This is a minimal, targeted, and correct fix for the SQLite readonly database error that was blocking nox -s unit_tests across all CI workers and test environments.


Checklist Results

Criterion Status Notes
Conventional Commit format fix(tests): fix create_template_db.py to create writable SQLite template database
ISSUES CLOSED footer ISSUES CLOSED: #9372 present in commit message
PR closing keyword Closes #9372 in PR description
Milestone assigned v3.2.0
Type/* label (exactly one) Type/Bug
CI: lint Successful in 4m34s
CI: typecheck Successful in 5m13s
CI: quality Successful in 5m9s
CI: security Successful in 5m22s
CI: unit_tests Successful in 12m2s
CI: integration_tests Successful in 10m53s
CI: e2e_tests Successful in 7m33s
CI: coverage Successful in 16m34s
CI: build Successful in 4m20s
CI: docker Successful in 1m31s
CI: helm Successful in 41s
CI: push-validation Successful in 36s
CI: status-check Successful
Acceptance criteria met All 4 AC from issue #9372 satisfied
CHANGELOG update N/A Test infrastructure fix; no user-facing behavior change

Code Review

scripts/create_template_db.py — The fix is correct and minimal:

# Added import os at top
import os

# After engine.dispose():
os.chmod(str(out), 0o664)
  • 0o664 (rw-rw-r--) is the appropriate permission: owner and group can write, world can read. This is the minimal permission needed to allow the test runner to copy and write to the template database.
  • Calling os.chmod after engine.dispose() is the correct placement — the file is fully written and closed before permissions are changed.
  • Using str(out) correctly converts the Path object for os.chmod.
  • The inline comments clearly explain the rationale, aiding future maintainability.

Issue Alignment

All acceptance criteria from issue #9372 are satisfied:

  • scripts/create_template_db.py now creates the template database with writable permissions (664)
  • nox -s unit_tests passes (CI unit_tests: success)
  • All existing tests continue to pass (all CI jobs green)
  • Fix verified in CI environment (run 13325, all jobs successful)

No Regressions

All 13 CI jobs passed. Coverage job succeeded, confirming the ≥97% threshold is maintained.


Automated by CleverAgents Bot
Supervisor: PR Review Pool | Agent: pr-reviewer
Worker: [AUTO-REV-9430]

## Code Review: APPROVED ✅ ### Summary This is a minimal, targeted, and correct fix for the SQLite readonly database error that was blocking `nox -s unit_tests` across all CI workers and test environments. --- ### Checklist Results | Criterion | Status | Notes | |---|---|---| | Conventional Commit format | ✅ | `fix(tests): fix create_template_db.py to create writable SQLite template database` | | ISSUES CLOSED footer | ✅ | `ISSUES CLOSED: #9372` present in commit message | | PR closing keyword | ✅ | `Closes #9372` in PR description | | Milestone assigned | ✅ | v3.2.0 | | Type/* label (exactly one) | ✅ | `Type/Bug` | | CI: lint | ✅ | Successful in 4m34s | | CI: typecheck | ✅ | Successful in 5m13s | | CI: quality | ✅ | Successful in 5m9s | | CI: security | ✅ | Successful in 5m22s | | CI: unit_tests | ✅ | Successful in 12m2s | | CI: integration_tests | ✅ | Successful in 10m53s | | CI: e2e_tests | ✅ | Successful in 7m33s | | CI: coverage | ✅ | Successful in 16m34s | | CI: build | ✅ | Successful in 4m20s | | CI: docker | ✅ | Successful in 1m31s | | CI: helm | ✅ | Successful in 41s | | CI: push-validation | ✅ | Successful in 36s | | CI: status-check | ✅ | Successful | | Acceptance criteria met | ✅ | All 4 AC from issue #9372 satisfied | | CHANGELOG update | ✅ N/A | Test infrastructure fix; no user-facing behavior change | --- ### Code Review **`scripts/create_template_db.py`** — The fix is correct and minimal: ```python # Added import os at top import os # After engine.dispose(): os.chmod(str(out), 0o664) ``` - `0o664` (`rw-rw-r--`) is the appropriate permission: owner and group can write, world can read. This is the minimal permission needed to allow the test runner to copy and write to the template database. - Calling `os.chmod` after `engine.dispose()` is the correct placement — the file is fully written and closed before permissions are changed. - Using `str(out)` correctly converts the `Path` object for `os.chmod`. - The inline comments clearly explain the rationale, aiding future maintainability. ### Issue Alignment All acceptance criteria from issue #9372 are satisfied: - ✅ `scripts/create_template_db.py` now creates the template database with writable permissions (664) - ✅ `nox -s unit_tests` passes (CI unit_tests: success) - ✅ All existing tests continue to pass (all CI jobs green) - ✅ Fix verified in CI environment (run 13325, all jobs successful) ### No Regressions All 13 CI jobs passed. Coverage job succeeded, confirming the ≥97% threshold is maintained. --- **Automated by CleverAgents Bot** Supervisor: PR Review Pool | Agent: pr-reviewer Worker: [AUTO-REV-9430]
Owner

Code Review Decision: APPROVED

All quality criteria met. The fix correctly addresses the SQLite readonly database error by adding os.chmod(str(out), 0o664) after database creation in scripts/create_template_db.py. All 13 CI jobs passed (including unit_tests, integration_tests, e2e_tests, and coverage). Commit format, closing keyword, milestone, and Type/* label all verified.


Automated by CleverAgents Bot
Supervisor: PR Review Pool | Agent: pr-reviewer
Worker: [AUTO-REV-9430]

**Code Review Decision: APPROVED ✅** All quality criteria met. The fix correctly addresses the SQLite readonly database error by adding `os.chmod(str(out), 0o664)` after database creation in `scripts/create_template_db.py`. All 13 CI jobs passed (including unit_tests, integration_tests, e2e_tests, and coverage). Commit format, closing keyword, milestone, and Type/* label all verified. --- **Automated by CleverAgents Bot** Supervisor: PR Review Pool | Agent: pr-reviewer Worker: [AUTO-REV-9430]
HAL9000 force-pushed fix/template-db-readonly-permissions from 02ccb1ee43
All checks were successful
CI / push-validation (pull_request) Successful in 36s
CI / helm (pull_request) Successful in 41s
CI / build (pull_request) Successful in 4m20s
CI / lint (pull_request) Successful in 4m34s
CI / quality (pull_request) Successful in 5m9s
CI / typecheck (pull_request) Successful in 5m13s
CI / security (pull_request) Successful in 5m22s
CI / e2e_tests (pull_request) Successful in 7m33s
CI / integration_tests (pull_request) Successful in 10m53s
CI / unit_tests (pull_request) Successful in 12m2s
CI / docker (pull_request) Successful in 1m31s
CI / coverage (pull_request) Successful in 16m34s
CI / status-check (pull_request) Successful in 1s
to 4c0f3e1da9
All checks were successful
CI / push-validation (push) Successful in 17s
CI / helm (push) Successful in 23s
CI / build (push) Successful in 30s
CI / lint (push) Successful in 43s
CI / quality (push) Successful in 48s
CI / typecheck (push) Successful in 53s
CI / security (push) Successful in 53s
CI / e2e_tests (push) Successful in 3m22s
CI / integration_tests (push) Successful in 6m42s
CI / unit_tests (push) Successful in 7m47s
CI / docker (push) Successful in 1m31s
CI / coverage (push) Successful in 12m9s
CI / status-check (push) Successful in 1s
CI / push-validation (pull_request) Successful in 13s
CI / helm (pull_request) Successful in 26s
CI / lint (pull_request) Successful in 33s
CI / build (pull_request) Successful in 38s
CI / quality (pull_request) Successful in 45s
CI / typecheck (pull_request) Successful in 49s
CI / security (pull_request) Successful in 55s
CI / e2e_tests (pull_request) Successful in 3m38s
CI / integration_tests (pull_request) Successful in 6m40s
CI / unit_tests (pull_request) Successful in 7m44s
CI / docker (pull_request) Successful in 10s
CI / coverage (pull_request) Successful in 12m9s
CI / status-check (pull_request) Successful in 3s
2026-04-14 22:14:48 +00:00
Compare
HAL9000 merged commit 4c0f3e1da9 into master 2026-04-14 22:26:41 +00:00
hurui200320 deleted branch fix/template-db-readonly-permissions 2026-04-15 04:01:30 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core!9430
No description provided.