Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def migrate_db():
# Index likely already exists
pass

# Add composite index for spatial queries with status filter
try:
conn.execute(text("CREATE INDEX ix_issues_status_lat_lon ON issues (status, latitude, longitude)"))
logger.info("Migrated database: Added composite index on status, latitude, longitude.")
except Exception:
# Index likely already exists
pass
Comment on lines +78 to +84
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Avoid silently swallowing composite-index creation errors.

A broad except Exception: pass hides real failures (e.g., missing columns or SQL errors), making perf regressions hard to diagnose. At minimum, log the exception so unexpected failures surface.

🛠️ Suggested adjustment
             try:
                 conn.execute(text("CREATE INDEX ix_issues_status_lat_lon ON issues (status, latitude, longitude)"))
                 logger.info("Migrated database: Added composite index on status, latitude, longitude.")
-            except Exception:
-                # Index likely already exists
-                pass
+            except Exception as exc:
+                # Index might already exist; keep visibility for unexpected failures
+                logger.debug("Skipping composite index creation: %s", exc)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Add composite index for spatial queries with status filter
try:
conn.execute(text("CREATE INDEX ix_issues_status_lat_lon ON issues (status, latitude, longitude)"))
logger.info("Migrated database: Added composite index on status, latitude, longitude.")
except Exception:
# Index likely already exists
pass
# Add composite index for spatial queries with status filter
try:
conn.execute(text("CREATE INDEX ix_issues_status_lat_lon ON issues (status, latitude, longitude)"))
logger.info("Migrated database: Added composite index on status, latitude, longitude.")
except Exception as exc:
# Index might already exist; keep visibility for unexpected failures
logger.debug("Skipping composite index creation: %s", exc)
🧰 Tools
🪛 Ruff (0.14.14)

[error] 82-84: try-except-pass detected, consider logging the exception

(S110)


[warning] 82-82: Do not catch blind exception: Exception

(BLE001)

🤖 Prompt for AI Agents
In `@backend/init_db.py` around lines 78 - 84, The composite index creation block
currently swallows all exceptions; change the except to capture the exception
object (e.g., except Exception as e) and log the failure using the module logger
(e.g., logger.exception or logger.error with exc_info) so unexpected SQL/column
errors are recorded while still allowing the migration to continue; update the
try/except around conn.execute(text("CREATE INDEX ix_issues_status_lat_lon ON
issues (status, latitude, longitude)")) to log the exception details rather than
using a bare pass.


# Add location column
try:
conn.execute(text("ALTER TABLE issues ADD COLUMN location VARCHAR"))
Expand Down
5 changes: 4 additions & 1 deletion backend/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from sqlalchemy import Column, Integer, String, DateTime, Float, Text, ForeignKey, Enum
from sqlalchemy import Column, Integer, String, DateTime, Float, Text, ForeignKey, Enum, Index
from sqlalchemy.types import TypeDecorator
from backend.database import Base
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -105,6 +105,9 @@ class EscalationAudit(Base):

class Issue(Base):
__tablename__ = "issues"
__table_args__ = (
Index('ix_issues_status_lat_lon', 'status', 'latitude', 'longitude'),
)

id = Column(Integer, primary_key=True, index=True)
reference_id = Column(String, unique=True, index=True) # Secure reference for government updates
Expand Down
Loading