Skip to content

refactor(tools): extract shared default_db_warning helper for SQL too…#1027

Merged
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
Davidson3556:refactor/shared-default-db-warning-893
Apr 28, 2026
Merged

refactor(tools): extract shared default_db_warning helper for SQL too…#1027
muddlebee merged 3 commits intoTracer-Cloud:mainfrom
Davidson3556:refactor/shared-default-db-warning-893

Conversation

@Davidson3556
Copy link
Copy Markdown
Contributor

Fixes #893

Describe the changes you have made in this PR -

Added a shared default_db_warning(db_name) helper under app/tools/utils/db_warnings.py and 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:

  • AzureSQLCurrentQueriesTool
  • AzureSQLSlowQueriesTool
  • PostgreSQLCurrentQueriesTool
  • PostgreSQLSlowQueriesTool
  • MySQLCurrentProcessesTool
  • MariaDBProcessListTool

Also added:

  • tests/tools/test_db_warnings.py — direct unit tests for the helper
  • Two warning behavior tests per tool (warning present when database omitted, absent when provided)

Demo/Screenshot for feature changes and bug fixes -

Screenshot 2026-04-28 at 01 39 45

Did you use AI assistance?

  • Yes, I used AI assistance

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:

The six SQL tools each had an identical block: check if database was None, set a default, then attach a warning string to the result dict. The only variation was the default DB name (master, postgres, or mysql). The fix is a one-line function default_db_warning(db_name: str) -> str in app/tools/utils/db_warnings.py that 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

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • I have added thorough tests
  • My code follows the project's style guidelines and conventions

…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-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR extracts a repeated inline warning string across six SQL tools into a single default_db_warning(db_name) helper in app/tools/utils/db_warnings.py, and adds thorough unit and integration tests for the new helper and each migrated tool. No behaviour changes — the warning key, text, and default DB names are all identical to before.

Confidence Score: 5/5

Safe 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 from __future__ import annotations import in the new helper file, which is a P2 style issue and does not block merge

app/tools/utils/db_warnings.py — minor style fix needed (missing future annotations import)

Important Files Changed

Filename Overview
app/tools/utils/db_warnings.py New shared helper — correct logic, but missing from __future__ import annotations required by project style guide
app/tools/utils/init.py Correctly exports default_db_warning in __all__ with a descriptive inline comment
app/tools/AzureSQLCurrentQueriesTool/init.py Migrated inline warning to default_db_warning("master") — logic unchanged, clean substitution
app/tools/AzureSQLSlowQueriesTool/init.py Migrated inline warning to default_db_warning("master") — logic unchanged, clean substitution
app/tools/PostgreSQLCurrentQueriesTool/init.py Migrated inline warning to default_db_warning("postgres") — logic unchanged
app/tools/PostgreSQLSlowQueriesTool/init.py Migrated inline warning to default_db_warning("postgres") — logic unchanged
app/tools/MySQLCurrentProcessesTool/init.py Migrated inline warning to default_db_warning("mysql") — logic unchanged
app/tools/MariaDBProcessListTool/init.py Migrated inline warning to default_db_warning("mysql") — logic unchanged
tests/tools/test_db_warnings.py New unit tests cover all three DB name variants, prefix, template consistency, and inequality — good coverage

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
Loading

Reviews (1): Last reviewed commit: "refactor(tools): extract shared default_..." | Re-trigger Greptile

Comment thread app/tools/utils/db_warnings.py
@Davidson3556
Copy link
Copy Markdown
Contributor Author

Davidson3556 commented Apr 28, 2026

@VaibhavUpreti @muddlebee kindly review

muddlebee

This comment was marked as outdated.

@muddlebee muddlebee self-requested a review April 28, 2026 09:09
@muddlebee
Copy link
Copy Markdown
Collaborator

approved my mistake. still need review..

@muddlebee muddlebee merged commit c9384b6 into Tracer-Cloud:main Apr 28, 2026
7 checks passed
@muddlebee
Copy link
Copy Markdown
Collaborator

@Davidson3556 thank you, good work 👍

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.

Extract one shared helper for the repeated default-database warnings in SQL tools

2 participants