Skip to content

Fix Issue(title=...) TypeError in test_field_officer.py and restore detection.py startup fix#588

Draft
Copilot wants to merge 2 commits intobolt/optimize-field-officer-visit-history-11841172508591724724from
copilot/sub-pr-565
Draft

Fix Issue(title=...) TypeError in test_field_officer.py and restore detection.py startup fix#588
Copilot wants to merge 2 commits intobolt/optimize-field-officer-visit-history-11841172508591724724from
copilot/sub-pr-565

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 24, 2026

Issue model has no title column, so the original test_field_officer.py raised TypeError at test collection time. A prior Netlify config commit (06f021b) also accidentally deleted the test file and re-introduced a NameError in detection.py that had already been fixed.

Description

backend/tests/test_field_officer.py — recreated with:

  • Removed invalid title= kwarg from Issue(...) constructor; kept only real model fields (description, category, status, latitude, longitude)
  • Added in-memory SQLite db_session fixture (creates/drops schema per test) and a client fixture that overrides get_db so the endpoint hits the test DB
  • Added module-level mocks for heavy optional dependencies (google.generativeai, magic, telegram, speech_recognition, pydub, etc.) so backend.main imports cleanly in CI without those packages

backend/routers/detection.py — restored removal of undefined httpx.AsyncClient type hint on detect_emotion_endpoint. httpx is not imported in this module; the annotation caused a NameError at startup. The Depends(get_http_client) injection is unaffected.

# Before (broken — httpx not imported)
client: httpx.AsyncClient = backend.dependencies.Depends(get_http_client)

# After
client = backend.dependencies.Depends(get_http_client)

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Code style update (formatting, renaming)
  • ♻️ Refactoring (no functional changes)
  • ⚡ Performance improvement
  • ✅ Test update

Related Issue

Testing Done

  • Tested locally
  • Added/updated tests
  • All tests passing

Screenshots (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Co-Authors


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.


Summary by cubic

Refines the field officer visit history lookup to reduce DB load and stabilize results. Adds a regression test for the endpoint (correct Issue model) and restores /api/detect-emotion client injection by removing the httpx.AsyncClient type in favor of get_http_client.

Written for commit 75dc2f0. Summary will update on new commits.

Copilot AI changed the title [WIP] [WIP] Address feedback on field officer visit history lookup optimization Fix Issue(title=...) TypeError in test_field_officer.py and restore detection.py startup fix Mar 24, 2026
Copilot AI requested a review from RohanExploit March 24, 2026 17:23
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.

2 participants