Skip to content

fix: handle # character in SQLite database file paths - #718

Merged
kalbasit merged 2 commits into
mainfrom
fix-sqlite
Feb 3, 2026
Merged

kalbasit merged 2 commits into
mainfrom
fix-sqlite

Conversation

@kalbasit

@kalbasit kalbasit commented Feb 3, 2026

Copy link
Copy Markdown
Owner

This fixes a critical bug where test names containing '#' characters
(like "TestCacheBackends/SQLite#01") were causing database path
parsing issues.

The problem: When creating a SQLite database URL like
sqlite:/path/to/Test#01/db.sqlite, Go's url.Parse() treats
everything after '#' as a URL fragment. This caused database.Open()
to use a different path than the migration tools, resulting in:

  • Migrations running on /path/to/Test#01/db.sqlite
  • Application opening /path/to/Test/db.sqlite (different file!)

This manifested as flaky tests that failed ~50% of the time with
"no such table: config" errors, because the application was literally
opening an empty database file instead of the migrated one.

Changes:

  1. Modified openSQLite() to reconstruct the full file path by
    appending the URL fragment (if present) back to the path.
  2. Added WAL checkpoint after migrations to ensure changes are
    immediately visible to new connections (defense in depth).

Co-Authored-By: Claude Sonnet 4.5 [email protected]

This fixes a critical bug where test names containing '#' characters
(like "TestCacheBackends/SQLite#01") were causing database path
parsing issues.

The problem: When creating a SQLite database URL like
`sqlite:/path/to/Test#01/db.sqlite`, Go's url.Parse() treats
everything after '#' as a URL fragment. This caused database.Open()
to use a different path than the migration tools, resulting in:
- Migrations running on /path/to/Test#01/db.sqlite
- Application opening /path/to/Test/db.sqlite (different file!)

This manifested as flaky tests that failed ~50% of the time with
"no such table: config" errors, because the application was literally
opening an empty database file instead of the migrated one.

Changes:
1. Modified openSQLite() to reconstruct the full file path by
   appending the URL fragment (if present) back to the path.
2. Added WAL checkpoint after migrations to ensure changes are
   immediately visible to new connections (defense in depth).

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 3, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a significant issue where SQLite database paths containing '#' characters were incorrectly parsed, causing applications to interact with an unmigrated database. The fix involves a precise reassembly of the database path to ensure consistency between migration tools and the application. Additionally, a WAL checkpoint mechanism has been implemented post-migration to guarantee immediate data visibility and robustness, particularly within test environments.

Highlights

  • SQLite Path Handling Fix: Corrected a critical bug where SQLite database file paths containing the '#' character were misinterpreted by Go's url.Parse(), leading to applications opening an incorrect or empty database file. The openSQLite function now reconstructs the full path by re-appending any URL fragment that was originally part of the file path.
  • WAL Checkpointing for Consistency: Introduced a PRAGMA wal_checkpoint(TRUNCATE) command after database migrations in test helpers. This ensures that all changes are immediately written from the Write-Ahead Log (WAL) to the main database file, enhancing data consistency and preventing subtle issues, especially in rapid test cycles.
Changelog
  • pkg/database/database.go
    • Modified the openSQLite function to correctly handle SQLite database file paths that include the '#' character. It now checks for a URL fragment and appends it back to the path with a '#' separator if present, ensuring the full and correct file path is used.
  • testhelper/sqlite.go
    • Added a PRAGMA wal_checkpoint(TRUNCATE) command within the CreateMigrateDatabase function. This explicitly checkpoints the WAL, forcing all pending changes to be written to the main database file immediately after migrations, improving data consistency for subsequent database operations.
Activity
  • No human activity (comments, reviews, etc.) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

kalbasit commented Feb 3, 2026

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added bug Something isn't working go Pull requests that update go code labels Feb 3, 2026
@kalbasit
kalbasit enabled auto-merge (squash) February 3, 2026 20:57

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a critical bug in handling SQLite database file paths that contain the '#' character. The approach of reconstructing the path after url.Parse is correct in principle. However, the current implementation in pkg/database/database.go is not fully robust, as it fails to consider URLs where the path is stored in the Opaque field (e.g., sqlite:/path/to/db), which appears to be the case in your test suite. I've provided a critical comment with a code suggestion to make this logic more resilient by checking both u.Opaque and u.Path. The addition of a WAL checkpoint in the test helper is a solid defensive measure that should improve test stability.

Comment thread pkg/database/database.go Resolved
@kalbasit
kalbasit disabled auto-merge February 3, 2026 21:04
@codecov

codecov Bot commented Feb 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.16%. Comparing base (2699a2f) to head (6fa5410).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #718   +/-   ##
=======================================
  Coverage   79.16%   79.16%           
=======================================
  Files           2        2           
  Lines         456      456           
=======================================
  Hits          361      361           
  Misses         83       83           
  Partials       12       12           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 3, 2026
@kalbasit
kalbasit enabled auto-merge (squash) February 3, 2026 21:11
@kalbasit
kalbasit merged commit e41d05d into main Feb 3, 2026
15 checks passed
@kalbasit
kalbasit deleted the fix-sqlite branch February 3, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant