Skip to content

fix(database): remove dead case_sensitive_like pragma (#1346)#1353

Open
VanshajPoonia wants to merge 3 commits into
AOSSIE-Org:mainfrom
VanshajPoonia:fix/1346-pragma-case-sensitive-like
Open

fix(database): remove dead case_sensitive_like pragma (#1346)#1353
VanshajPoonia wants to merge 3 commits into
AOSSIE-Org:mainfrom
VanshajPoonia:fix/1346-pragma-case-sensitive-like

Conversation

@VanshajPoonia

@VanshajPoonia VanshajPoonia commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

PRAGMA case_sensitive_like = ON in get_db_connection() affected zero queries: the only LIKE query (db_get_folder_ids_by_path_prefix) uses a raw sqlite3.connect() that never ran the pragma. Removing it keeps LIKE case-insensitive (SQLite default) and avoids a latent footgun where migrating a LIKE query onto the shared helper would silently turn subfolder prefix matching case-sensitive on macOS/Windows.

Add regression tests asserting case-insensitive folder prefix matching.

Addressed Issues:

Fixes #1346

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: Codex

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Bug Fixes

    • Improved database integrity by enforcing stricter constraint checks during SQLite connections.
    • Removed case-sensitive LIKE behavior from connection setup, which may affect path and text matching consistency.
  • Tests

    • Added regression coverage for folder path prefix matching.
    • Verified matching works regardless of letter case and excludes folders outside the requested prefix.

PRAGMA case_sensitive_like = ON in get_db_connection() affected zero
queries: the only LIKE query (db_get_folder_ids_by_path_prefix) uses a
raw sqlite3.connect() that never ran the pragma. Removing it keeps LIKE
case-insensitive (SQLite default) and avoids a latent footgun where
migrating a LIKE query onto the shared helper would silently turn
subfolder prefix matching case-sensitive on macOS/Windows.

Add regression tests asserting case-insensitive folder prefix matching.
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@VanshajPoonia, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 67865f42-2507-46ee-a1c6-ced33c76876c

📥 Commits

Reviewing files that changed from the base of the PR and between 86930a6 and ff35454.

📒 Files selected for processing (1)
  • backend/tests/test_folders.py

Walkthrough

Removes PRAGMA case_sensitive_like = ON from get_db_connection(), which was dead configuration affecting no active queries. Adds a new test class TestFolderPathPrefixMatching with two regression tests verifying that db_get_folder_ids_by_path_prefix() performs case-insensitive prefix matching and excludes non-matching paths.

Fix for latent case_sensitive_like footgun

Layer / File(s) Summary
Remove case_sensitive_like pragma
backend/app/database/connection.py
PRAGMA case_sensitive_like = ON is removed from the SQLite initialization block in get_db_connection(); remaining PRAGMAs enforce foreign keys and CHECK constraints.
Regression tests for prefix matching
backend/tests/test_folders.py
Adds TestFolderPathPrefixMatching with a folders_db fixture using a patched temp DB, and two tests asserting case-insensitive prefix matching and correct exclusion of non-matching folder paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Python

Poem

🐇 A pragma once lurked in the connection,
Making LIKE queries an inconsistent selection.
I hopped through the code and pulled it right out,
Then wrote some tests to remove all doubt.
Case-insensitive paths — now that's what it's about! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely matches the main change: removing the dead case_sensitive_like pragma.
Linked Issues check ✅ Passed The PR removes the inconsistent pragma and adds regression tests for case-insensitive folder prefix matching, matching issue #1346.
Out of Scope Changes check ✅ Passed The only added work is regression testing for the same database behavior, with no unrelated scope introduced.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
backend/tests/test_folders.py (1)

853-858: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Fixture teardown can leak the fd/temp file if setup fails.

os.close(db_fd) / os.unlink(db_path) run only if db_create_folders_table() succeeds and the test reaches teardown. Wrapping cleanup in try/finally makes the fixture leak-safe.

♻️ Leak-safe teardown
         db_fd, db_path = tempfile.mkstemp()
-        with patch.object(folders_module, "DATABASE_PATH", db_path):
-            folders_module.db_create_folders_table()
-            yield folders_module
-        os.close(db_fd)
-        os.unlink(db_path)
+        try:
+            with patch.object(folders_module, "DATABASE_PATH", db_path):
+                folders_module.db_create_folders_table()
+                yield folders_module
+        finally:
+            os.close(db_fd)
+            os.unlink(db_path)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/tests/test_folders.py` around lines 853 - 858, The fixture teardown
around the temp database in the test setup is not leak-safe because cleanup only
runs after db_create_folders_table() succeeds. Update the fixture in
test_folders.py to keep the tempfile creation and DATABASE_PATH patching, but
wrap the yield and cleanup of db_fd and db_path in a try/finally so os.close and
os.unlink always execute even if setup fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/tests/test_folders.py`:
- Around line 839-875: The regression test currently exercises
db_get_folder_ids_by_path_prefix() through a direct SQLite path, so it won’t
catch a case-sensitivity regression in the shared-connection setup. Update
TestFolderPathPrefixMatching to route the prefix lookup through the
shared-connection helper used by app.database.folders (or add a dedicated test
that calls that helper directly) so the query actually covers the connection
path where PRAGMA case_sensitive_like would be applied.

---

Nitpick comments:
In `@backend/tests/test_folders.py`:
- Around line 853-858: The fixture teardown around the temp database in the test
setup is not leak-safe because cleanup only runs after db_create_folders_table()
succeeds. Update the fixture in test_folders.py to keep the tempfile creation
and DATABASE_PATH patching, but wrap the yield and cleanup of db_fd and db_path
in a try/finally so os.close and os.unlink always execute even if setup fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c861a4ae-10d0-43b7-95cf-cbcfb16f4cd5

📥 Commits

Reviewing files that changed from the base of the PR and between b3eee2c and 86930a6.

📒 Files selected for processing (2)
  • backend/app/database/connection.py
  • backend/tests/test_folders.py
💤 Files with no reviewable changes (1)
  • backend/app/database/connection.py

Comment thread backend/tests/test_folders.py
CodeRabbit flagged that the existing regression test for AOSSIE-Org#1346 only
exercises db_get_folder_ids_by_path_prefix(), which opens SQLite
directly and never goes through get_db_connection(). Add a test that
calls the shared helper directly so a future PRAGMA
case_sensitive_like = ON reintroduced there is caught immediately,
even before any production query relies on it.
os.close(db_fd) and os.unlink(db_path) only ran after
db_create_folders_table() succeeded, so a setup failure would leak the
fd and temp file. Wrap teardown in try/finally so cleanup always runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Dead/inconsistent PRAGMA case_sensitive_like in get_db_connection (affects no queries today, latent footgun)

1 participant