refactor(tools): extract shared default_db_warning helper for SQL too…#1027
Conversation
…ls (Tracer-Cloud#893) Replace six repeated inline warning strings across AzureSQL, PostgreSQL, MySQL, and MariaDB tools with a single helper in app/tools/utils/db_warnings.py. Add direct tests for the helper and warning behavior tests to all six tool modules.
Greptile SummaryThis PR extracts a repeated inline warning string across six SQL tools into a single Confidence Score: 5/5Safe to merge — pure refactor with no logic changes and full test coverage All six tool migrations are mechanically correct substitutions; the only finding is a missing app/tools/utils/db_warnings.py — minor style fix needed (missing future annotations import) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[SQL Tool called without database param] --> B{_db_defaulted?}
B -- Yes --> C[default_db_warning called with db_name]
C --> D[Warning string set on result dict]
D --> E[return result]
B -- No --> E
subgraph utils["app/tools/utils/db_warnings.py"]
C
end
subgraph callers["Callers"]
AZ1[AzureSQLCurrentQueriesTool - master]
AZ2[AzureSQLSlowQueriesTool - master]
PG1[PostgreSQLCurrentQueriesTool - postgres]
PG2[PostgreSQLSlowQueriesTool - postgres]
MY[MySQLCurrentProcessesTool - mysql]
MA[MariaDBProcessListTool - mysql]
end
AZ1 & AZ2 & PG1 & PG2 & MY & MA --> B
Reviews (1): Last reviewed commit: "refactor(tools): extract shared default_..." | Re-trigger Greptile |
|
@VaibhavUpreti @muddlebee kindly review |
|
approved my mistake. still need review.. |
|
@Davidson3556 thank you, good work 👍 |
Fixes #893
Describe the changes you have made in this PR -
Added a shared
default_db_warning(db_name)helper underapp/tools/utils/db_warnings.pyand migrated six SQL tools that were each repeating the same inline warning string to use it instead. The warning key (default_db_warning) and warning text are unchanged — only the source of truth moved to one place.Tools migrated:
AzureSQLCurrentQueriesToolAzureSQLSlowQueriesToolPostgreSQLCurrentQueriesToolPostgreSQLSlowQueriesToolMySQLCurrentProcessesToolMariaDBProcessListToolAlso added:
tests/tools/test_db_warnings.py— direct unit tests for the helperdatabaseomitted, absent when provided)Demo/Screenshot for feature changes and bug fixes -
Did you use AI assistance?
If you used AI assistance:
Explain your implementation approach:
The six SQL tools each had an identical block: check if
databasewasNone, set a default, then attach a warning string to the result dict. The only variation was the default DB name (master,postgres, ormysql). The fix is a one-line functiondefault_db_warning(db_name: str) -> strinapp/tools/utils/db_warnings.pythat returns the formatted warning. Each tool now calls that instead of hardcoding the string. No logic changed — the response key and warning text are identical to before.Checklist before requesting a review