Skip to content
Merged
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
2 changes: 1 addition & 1 deletion mindsdb_sdk/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get(self, name: str) -> Database:
"""
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]
Comment on lines 174 to 178

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.


def update(self, name: str, connection_args: Dict) -> Database:
Expand Down