Skip to content

Comments

Improve error message for non-existent database#218

Merged
lucas-koontz merged 2 commits intomainfrom
lucas-koontz-patch-1
Feb 12, 2026
Merged

Improve error message for non-existent database#218
lucas-koontz merged 2 commits intomainfrom
lucas-koontz-patch-1

Conversation

@lucas-koontz
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented Feb 12, 2026

Coverage

Coverage Report
FileStmtsMissCoverMissing
mindsdb_sdk
   agents.py1794774%29, 101, 104, 107, 110, 118, 126, 146, 167, 178, 181, 185, 187, 189, 191, 193, 195, 197, 261, 274, 285, 296, 299–303, 318, 327–331, 375, 383–384, 442, 450–451, 455, 486–488, 490–491, 518–519, 521
   databases.py58788%85–86, 149, 177, 188–194
   handlers.py37197%77
   jobs.py97793%40, 52, 80, 84, 146–149
   knowledge_bases.py1331886%70–73, 132–136, 160, 189, 196, 200–202, 206, 228–232, 242
   ml_engines.py42393%94, 126, 128
   models.py2111991%109, 140–141, 222, 231, 233, 303, 339, 349, 373, 398, 492, 500, 519, 535, 543, 568, 572, 585
   projects.py61198%158
   query.py13192%14
   server.py31294%86–87
   tables.py1301588%140–142, 145, 165, 192, 203–204, 209, 224, 227, 321, 342–347, 356, 376
   tree.py321650%18–19, 24–28, 41–57
   views.py37295%105, 138
mindsdb_sdk/connectors
   rest_api.py2445677%19–29, 35–36, 51, 55, 58–59, 79–81, 87–89, 108, 111, 118–121, 144, 158–166, 187–188, 223–226, 240–241, 295–300, 304–316
mindsdb_sdk/utils
   agents.py50492%72, 79–81
   mind.py47470%1–128
   openai.py853065%37–40, 83–85, 107, 148–158, 215–216, 234–240, 258–276
   table_schema.py21210%1–54
TOTAL158929781% 

Tests Skipped Failures Errors Time
26 0 💤 0 ❌ 0 🔥 6.090s ⏱️

Comment on lines 173 to 177
"""
databases = self._list_databases()
if name not in databases:
raise AttributeError("Database doesn't exist")
raise AttributeError(f"Database '{name}' doesn't exist")
return databases[name]

Choose a reason for hiding this comment

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

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 92%)

This function Databases.get duplicates existing code.

📍 Original Location:

mindsdb_sdk/projects.py:152-161

Function: Projects.get

💡 Recommendation:
Extract this pattern into a template method in the CollectionBase parent class:

class CollectionBase:
    def _get_with_validation(self, name: str, list_method, constructor, resource_type: str):
        """Template method for validated get operations"""
        items = list_method()
        if name not in items:
            raise AttributeError(f"{resource_type} '{name}' doesn't exist")
        return constructor(name, items) if callable(constructor) else items[name]

Then both Databases.get() and Projects.get() can call this template method, reducing duplication and ensuring consistent error messages across all collection managers.

Consider importing and reusing the existing function instead of duplicating the logic.

Copy link
Contributor

@MinuraPunchihewa MinuraPunchihewa left a comment

Choose a reason for hiding this comment

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

@lucas-koontz If you want to release this as a patch, you will need to update the version as well.

@github-project-automation github-project-automation bot moved this from to review to approved in Tracking PRs Feb 12, 2026
@lucas-koontz lucas-koontz merged commit 607c2de into main Feb 12, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from approved to merged in Tracking PRs Feb 12, 2026
@lucas-koontz lucas-koontz deleted the lucas-koontz-patch-1 branch February 12, 2026 17:33
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: merged

Development

Successfully merging this pull request may close these issues.

3 participants