@cryptotaxi247 / CoPilot / commits / f1ede329

feat: enhance fetch_settings to support case-insensitive comparisons (#679)

taylor_socfortress committed Feb 4, 2026 at 09:28 UTC f1ede3298d8f95d07f68985c172d3cac61b4b30e
1 file changed +25 -7
backend/app/incidents/services/incident_alert.py
+25 -7
@@ -11,6 +11,7 @@ from fastapi import HTTPException
11 from loguru import logger
12 from sqlalchemy.ext.asyncio import AsyncSession
13 from sqlalchemy.future import select
14 +from sqlalchemy.sql import func
15
16 from app.connectors.shuffle.schema.integrations import ExecuteWorkflowRequest
17 from app.connectors.shuffle.services.integrations import execute_workflow
@@ -47,7 +48,7 @@ from app.integrations.alert_escalation.schema.escalate_alert import CustomerCode
48 from app.integrations.routes import get_customer_by_auth_key
49
50
50 -async def fetch_settings(field: str, value: str, session: AsyncSession):
51 +async def fetch_settings(field: str, value: str, session: AsyncSession, case_insensitive: bool = False):
52 """
53 Fetch settings based on the field and value.
54
@@ -55,16 +56,26 @@ async def fetch_settings(field: str, value: str, session: AsyncSession):
56 field (str): The field to check.
57 value (str): The value to check.
58 session (AsyncSession): The database session.
59 + case_insensitive (bool): Whether to perform case-insensitive comparison.
60
61 Returns:
62 AlertCreationSettings: The settings if found, None otherwise.
63 """
62 - logger.info(f"Checking if {field}: {value} is valid.")
63 - result = await session.execute(
64 - select(AlertCreationSettings).where(
65 - getattr(AlertCreationSettings, field) == value,
66 - ),
67 - )
64 + logger.info(f"Checking if {field}: {value} is valid (case_insensitive={case_insensitive}).")
65 +
66 + if case_insensitive:
67 + result = await session.execute(
68 + select(AlertCreationSettings).where(
69 + func.lower(getattr(AlertCreationSettings, field)) == value.lower(),
70 + ),
71 + )
72 + else:
73 + result = await session.execute(
74 + select(AlertCreationSettings).where(
75 + getattr(AlertCreationSettings, field) == value,
76 + ),
77 + )
78 +
79 settings = result.scalars().first()
80 logger.info(f"Settings: {settings}")
81 return settings
@@ -83,6 +94,13 @@ async def is_customer_code_valid(customer_code: str, session: AsyncSession) -> A
94 """
95 settings = await fetch_settings("customer_code", customer_code, session)
96
97 + if settings:
98 + return settings
99 +
100 + # If no settings found customer_code, try with the lowered customer_name
101 + normalized_code = customer_code.lower().replace("_", " ")
102 + settings = await fetch_settings("customer_name", normalized_code, session, case_insensitive=True)
103 +
104 if settings:
105 return settings
106