Skip to content

Conversation

@ZoranPandovski
Copy link
Member

Add Tree API implementation

@entelligence-ai-pr-reviews
Copy link

🔒 Entelligence AI Vulnerability Scanner

No security vulnerabilities found!

Your code passed our comprehensive security analysis.

📊 Files Analyzed: 5 files


@entelligence-ai-pr-reviews
Copy link

Review Summary

🏷️ Draft Comments (1)

Skipped posting 1 draft comments that were valid but scored below your review threshold (>=13/15). Feel free to update them here.

mindsdb_sdk/tree.py (1)

22-37, 39-57: from_dict and to_dict recursively process all children, which can cause stack overflows or high memory usage for very deep or large trees; consider iterative traversal for scalability.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Refactor mindsdb_sdk/tree.py lines 22-57 to replace the recursive implementations of `from_dict` and `to_dict` with iterative versions. The current recursion can cause stack overflows or high memory usage for very deep or large trees. Use explicit stacks to traverse the tree structure iteratively in both methods, ensuring functional equivalence and preserving all fields.

🔍 Comments beyond diff scope (1)
mindsdb_sdk/server.py (1)

36-36: super().__init__(self, api, 'mindsdb') incorrectly passes self as the first argument, which can cause incorrect initialization and runtime errors.
Category: correctness


@entelligence-ai-pr-reviews
Copy link

Review Summary

🏷️ Draft Comments (17)

Skipped posting 17 draft comments that were valid but scored below your review threshold (>=13/15). Feel free to update them here.

mindsdb_sdk/agents.py (2)

84-90: skills and data default to mutable objects ([], {}) in Agent.__init__, which can cause shared state across instances and unpredictable bugs.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 3/5
  • Urgency Impact: 3/5
  • Total Score: 10/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/agents.py, lines 84-90, the default arguments for `skills`, `data`, `params`, and `skills_extra_parameters` in the Agent class constructor are mutable objects (`[]`, `{}`). This can cause shared state between Agent instances. Change their defaults to `None` and update the constructor to initialize them to empty lists/dicts if they are None.

325-368: add_files and add_file methods allow arbitrary file paths to be uploaded without validation, enabling path traversal or unauthorized file access if user input is not strictly controlled.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 3/5
  • Urgency Impact: 4/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/agents.py, lines 325-368, the `add_files` and `add_file` methods accept arbitrary file paths and pass them to file upload logic without validation, which could allow path traversal or unauthorized file access if user input is not strictly controlled. Add validation to ensure that file paths do not contain '..', are not absolute paths, and are strings. Raise a ValueError if validation fails. Apply this check before any file operations in both methods.

mindsdb_sdk/config.py (1)

67-75: api_key values are accepted and stored in config without any encryption or masking, risking sensitive credential exposure if config is leaked or logged.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 1/5
  • Urgency Impact: 3/5
  • Total Score: 8/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/config.py, lines 67-75, the `api_key` is stored in the config dictionary and passed to `self.api.update_config` without any masking or encryption. This exposes sensitive credentials if the config is logged or leaked. Update the code so that the `api_key` is masked (e.g., replaced with '***REDACTED***') before storing or transmitting it.

mindsdb_sdk/connectors/rest_api.py (2)

144-150: read_file_as_bytes opens files with mode 'rb+', which will fail if the file does not already exist and is not needed for reading; should use 'rb' for reading bytes.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/connectors/rest_api.py, lines 144-150, the function `read_file_as_bytes` opens files with mode `'rb+'`, which will fail if the file does not exist and is unnecessary for reading. Change the file open mode from `'rb+'` to `'rb'` to ensure correct file reading behavior.

221-231: get_file_metadata fetches all file metadata and iterates to find one file, causing O(n) time and bandwidth for large file sets; this does not scale and degrades performance.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 2/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

The function `get_file_metadata` in mindsdb_sdk/connectors/rest_api.py (lines 221-231) retrieves metadata for a single file by fetching all file metadata and iterating to find the match. This is O(n) in time and bandwidth, which is inefficient for large file sets. If the backend supports a direct endpoint for single file metadata, refactor this function to use it. If not, request such an endpoint from the backend team to avoid this scalability bottleneck.

mindsdb_sdk/handlers.py (1)

66-77: Handlers.get performs a linear search over all handlers by calling self.list() and iterating, which is inefficient for large handler sets and causes repeated SQL queries if called frequently.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize the `get` method in mindsdb_sdk/handlers.py (lines 66-77). The current implementation performs a linear search over all handlers by calling `self.list()` and iterating, which is inefficient for large handler sets and causes repeated SQL queries if called frequently. Refactor the method to build a dictionary mapping handler names to handler objects (using a dictionary comprehension) and perform a direct lookup. Preserve the original code formatting.

mindsdb_sdk/jobs.py (3)

27-34: Job._update does not check for missing keys in data, causing KeyError if any expected field is absent.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 4/5
  • Urgency Impact: 3/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/jobs.py, lines 27-34, the `Job._update` method directly accesses keys in the `data` dict, which will raise a `KeyError` if any expected field is missing. Update the method to use `data.get(...)` for each field to prevent runtime exceptions when fields are absent.

108-124: Jobs._list loads all job records into memory and creates a Job object for each, which can cause high memory/CPU usage for large job tables.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 4/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/jobs.py, lines 108-124, the `_list` method loads all job records into memory and creates a Job object for each, which can cause high memory/CPU usage for large job tables. Add a `limit` parameter (default 1000) to the method and apply it to the query (e.g., `ast_query.limit = limit`) to prevent excessive resource usage. Update the method signature and usage accordingly.

67-85,151-231: Jobs.create and Job.add_query accept arbitrary SQL strings in query_str and add_query, allowing SQL injection if untrusted user input is passed, leading to unauthorized data access or modification.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 2/5
  • Urgency Impact: 3/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/jobs.py, lines 67-85 and 151-231, the `Job.add_query` and `Jobs.create` methods accept arbitrary SQL strings via `query_str` and `add_query`, which can lead to SQL injection if untrusted input is passed. Update both methods to reject queries containing multiple statements (e.g., ';'), SQL comments ('--', '/*', '*/'), or other suspicious patterns by raising a ValueError. Ensure only single, safe SQL statements are accepted.

mindsdb_sdk/knowledge_bases.py (1)

191-202: insert method processes large lists or DataFrames by recursively chunking and inserting, but each chunk is handled via a new function call, leading to deep recursion and potential stack overflow for very large datasets.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 4/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Refactor the `insert` method in mindsdb_sdk/knowledge_bases.py (lines 191-202) to avoid deep recursion when processing large DataFrames or lists. Instead of recursively calling `insert` for each chunk, introduce a helper method (e.g., `_insert_chunk`) that handles the actual API call for each chunk. Update the chunking logic to call this helper directly, ensuring the call stack does not grow with the number of chunks.

mindsdb_sdk/ml_engines.py (3)

91-92: get method lowercases the input name but does not lowercase item.name, causing lookups to fail for engines with uppercase names.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 12/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/ml_engines.py, lines 91-92, the `get` method lowercases the input `name` but compares it to `item.name` without lowercasing. This causes lookups to fail for engines with uppercase names. Update the comparison to `if item.name.lower() == name:` to ensure case-insensitive matching.

91-94: get method calls self.list() on every lookup, causing an O(n) scan and repeated server queries for each call; this is inefficient for frequent or repeated lookups.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize the `get` method in mindsdb_sdk/ml_engines.py (lines 91-94). The current implementation calls `self.list()` and iterates through all engines for every lookup, which is inefficient for frequent or repeated lookups. Refactor the method to build a dictionary mapping engine names to engine objects (using a dict comprehension) and perform a direct lookup. Preserve the original code formatting.

115-132: create_byom allows arbitrary Python code and requirements to be uploaded without validation, enabling remote code execution on the server if an attacker controls code or requirements.

📊 Impact Scores:

  • Production Impact: 5/5
  • Fix Specificity: 2/5
  • Urgency Impact: 4/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/ml_engines.py, lines 115-132, the `create_byom` method allows arbitrary Python code and requirements to be uploaded, which could enable remote code execution if an attacker controls these inputs. Add a permission check to ensure only authorized users can upload BYOM engines, and consider static code analysis or package restrictions. Insert this check before calling `self.api.upload_byom`.

mindsdb_sdk/models.py (1)

232-233: wait_complete raises KeyError if 'error' key is missing in self.data when status is 'error', causing a crash instead of a meaningful exception.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 12/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/models.py, lines 232-233, the code raises a KeyError if 'error' is not present in self.data when status == 'error'. Update the code to use self.data.get('error', 'Unknown error') to avoid crashing and provide a meaningful error message.

mindsdb_sdk/tables.py (1)

55-57,67-69,89-93: copy.deepcopy(self) is used in filter, limit, and track methods, which can be expensive for large Table objects and is unnecessary for shallow state changes.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 2/5
  • Urgency Impact: 2/5
  • Total Score: 6/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/tables.py, lines 55-57, 67-69, and 89-93, the methods `filter`, `limit`, and `track` use `copy.deepcopy(self)` to clone Table objects. This is inefficient and can cause significant performance overhead for large objects. Refactor these methods to use a lightweight custom copy constructor that only copies the necessary attributes (`_filters`, `_limit`, `_track_column`) instead of deep copying the entire object.

mindsdb_sdk/views.py (2)

137-139: self._list_views() is called in get for every lookup, causing a full API call and DataFrame filter even for single lookups; this is inefficient for frequent access.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/views.py, lines 137-139, the `get` method calls `self._list_views()` to check for existence, which results in a full API call and DataFrame filter for every lookup. Refactor to call `self._list_views()` once, store the result in a variable, and use that for the existence check and subsequent logic.

92-116: sql parameter in create method is directly used in CreateView AST without sanitization, allowing SQL injection if untrusted input is passed.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 3/5
  • Urgency Impact: 4/5
  • Total Score: 11/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/views.py, lines 92-116, the `create` method uses the `sql` parameter directly in the `CreateView` AST, which allows SQL injection if untrusted input is passed. Please add validation to ensure that `sql` is a single SELECT statement and does not contain multiple statements or semicolons. Reject any input that does not start with 'SELECT' or contains a semicolon.

🔍 Comments beyond diff scope (5)
mindsdb_sdk/connectors/rest_api.py (2)

135-139: objects_tree method allows unsanitized item path input, enabling path traversal to access unauthorized API endpoints or sensitive resources.
Category: security


171-178: read_file_as_webpage fetches arbitrary URLs without validation, enabling SSRF attacks to internal services or sensitive endpoints.
Category: security


mindsdb_sdk/server.py (1)

33-33: super().__init__(self, api, 'mindsdb') passes self as the first argument, which is incorrect and can cause runtime errors or unexpected behavior in the class hierarchy.
Category: correctness


mindsdb_sdk/tables.py (1)

140-140: sql in insert method can be a tuple instead of a string when inserting from a Query without a database, causing runtime errors in downstream SQL execution.
Category: correctness


mindsdb_sdk/views.py (1)

90-90: View constructor is called as View(self.project, name), but View inherits from Table which expects arguments (api, name, project); this will cause incorrect initialization and possible runtime errors.
Category: correctness


- Make objects_tree return DataFrame consistently with other REST API methods
- Fix views.py to use DataFrame filtering instead of complex TreeNode conversion
- Update server.py and databases.py to handle DataFrame->TreeNode conversion
- All SDK tests now passing
@github-actions
Copy link

github-actions bot commented Aug 29, 2025

Coverage

Coverage Report
FileStmtsMissCoverMissing
mindsdb_sdk
   agents.py2176769%30, 106, 109, 112, 115, 123, 131, 151, 172, 183, 186, 190, 192, 194, 196, 198, 200, 202, 204, 206, 213, 277, 290, 301, 312, 315–319, 334, 343–347, 391, 399–400, 458, 466–467, 471, 501–509, 517–519, 521–522, 548–561, 573–574, 576
   databases.py53492%85–86, 148, 176
   handlers.py39197%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.py2101991%109, 140–141, 222, 231, 233, 303, 339, 348, 372, 397, 491, 499, 518, 534, 542, 567, 571, 584
   projects.py63198%160
   query.py13192%14
   server.py33294%88–89
   skills.py53983%43, 45, 49, 58–60, 76–80, 122
   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.py2675380%19–29, 35–36, 51, 55, 58–59, 79–81, 102, 105, 112–115, 138, 152–160, 181–182, 217–220, 234–235, 289–294, 298–310
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
TOTAL170332081% 

Tests Skipped Failures Errors Time
31 0 💤 0 ❌ 0 🔥 11.455s ⏱️

@entelligence-ai-pr-reviews
Copy link

Review Summary

🏷️ Draft Comments (14)

Skipped posting 14 draft comments that were valid but scored below your review threshold (>=13/15). Feel free to update them here.

.github/workflows/test_prs.yml (1)

14-14: python-version matrix omits Python 3.7, which may cause tests to miss regressions or incompatibilities for users still on 3.7.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 5/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In .github/workflows/test_prs.yml, at line 14, the Python version matrix no longer includes 3.7. This can cause missed regressions for users on Python 3.7. Please add '3.7' back to the python-version matrix so that CI tests run on all supported versions.

mindsdb_sdk/connectors/rest_api.py (3)

144-150: read_file_as_bytes opens files with mode 'rb+', which will fail if the file does not already exist and is not needed for reading; should use 'rb' to avoid raising FileNotFoundError unnecessarily.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 5/5
  • Urgency Impact: 2/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/connectors/rest_api.py, lines 144-150, the function `read_file_as_bytes` opens files with mode `'rb+'`, which is incorrect for reading and will fail if the file does not exist. Change the open mode to `'rb'` to ensure correct file reading and avoid unnecessary exceptions.

222-231: get_file_metadata fetches all file metadata and iterates to find one file, causing O(n) time and bandwidth for large file sets.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 8/15

🤖 AI Agent Prompt (Copy & Paste Ready):

The function `get_file_metadata` in mindsdb_sdk/connectors/rest_api.py (lines 222-231) retrieves metadata for a single file by fetching all file metadata and iterating to find the match. This is O(n) in time and bandwidth, which is inefficient for large file sets. If the backend supports a direct endpoint for single file metadata, use it. Otherwise, request the backend team to add such an endpoint. If not possible, document this inefficiency and consider caching the metadata if this operation is frequent.

171-178: read_file_as_webpage (lines 171-178) fetches arbitrary URLs without validation, enabling SSRF attacks that could expose internal services or sensitive data.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 4/5
  • Urgency Impact: 4/5
  • Total Score: 12/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/connectors/rest_api.py, lines 171-178, the `read_file_as_webpage` method fetches arbitrary URLs without validation, allowing SSRF attacks. Update this function to only allow http(s) URLs and block requests to localhost or private/internal IP addresses. Add URL scheme checks and resolve the hostname to block internal IPs before making the request.

mindsdb_sdk/databases.py (1)

86-95: _list_databases fetches all database rows and constructs a full Database object for each, which can be expensive for large numbers of databases; this may cause high memory and CPU usage at scale.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 2/5
  • Urgency Impact: 2/5
  • Total Score: 6/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/databases.py, lines 86-95, the `_list_databases` method eagerly instantiates a `Database` object for every row, which can be expensive for large numbers of databases. Refactor this method to use a lazy instantiation approach (e.g., a factory or similar) so that `Database` objects are only created when accessed, reducing memory and CPU usage for large datasets.

mindsdb_sdk/handlers.py (1)

66-77: Handlers.get performs a linear search over all handlers by calling self.list() and iterating, which is O(n) and can be slow for large handler sets or frequent lookups.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize the `get` method in mindsdb_sdk/handlers.py (lines 66-77). The current implementation performs a linear search over all handlers, which is inefficient for large handler sets or frequent lookups. Refactor it to build a dictionary mapping handler names to handler objects for O(1) lookup, while preserving the original logic and formatting.

mindsdb_sdk/ml_engines.py (2)

91-92: get method compares item.name to name after lowercasing name, but item.name may not be lowercased, causing missed matches for engines with uppercase letters.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 12/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/ml_engines.py, lines 91-92, the `get` method compares `item.name` to `name` after lowercasing `name`, but does not lowercase `item.name`. This causes lookups to fail for engines with uppercase letters in their names. Update the comparison to `if item.name.lower() == name:` to ensure case-insensitive matching.

64-82: list() method fetches all ML engines and then reconstructs a list of MLEngine objects for every call, causing repeated full-table scans and object creation when used in loops or by get(); this is inefficient for large numbers of engines.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/ml_engines.py, lines 64-82, the `list()` method fetches and reconstructs all ML engine objects on every call, which is inefficient for large numbers of engines and when called repeatedly (e.g., by `get()`). Refactor this method to cache the result after the first call (e.g., using a private attribute like `_ml_engines_cache`), and return the cached list on subsequent calls. Ensure the cache is invalidated if engines are created or dropped.

mindsdb_sdk/models.py (2)

233-233: wait_complete raises KeyError if 'error' key is missing in self.data when status is 'error', causing a crash instead of a meaningful exception.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 12/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/models.py, line 233, the code raises a KeyError if 'error' is not present in self.data when status is 'error'. Change the line to use self.data.get('error', 'Unknown error') to avoid crashing and provide a meaningful error message.

630-633: Models.list() loads all model records into memory and instantiates all as objects, which can cause high memory/CPU usage for large model sets.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/models.py, lines 630-633, the `Models.list()` method loads all model records into memory and instantiates all as objects, which can cause high memory and CPU usage for large model sets. Refactor this to return a generator expression instead of a list, so that model objects are created lazily and memory usage is reduced for large datasets.

mindsdb_sdk/projects.py (1)

139-142: Projects.list() and Projects.get() call _list_projects() which issues a full table scan on information_schema.databases without filtering by project name, causing O(n) lookup and unnecessary data transfer for large numbers of databases.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 4/5
  • Urgency Impact: 2/5
  • Total Score: 8/15

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize the `_list_projects` method in `mindsdb_sdk/projects.py` (lines 139-142) to accept an optional `name` parameter. If `name` is provided, filter the SQL query to only fetch that project, reducing unnecessary data transfer and improving lookup efficiency for large numbers of projects. Update all usages in `get()` and `list()` accordingly.

mindsdb_sdk/tables.py (1)

55-56: copy.deepcopy(self) is used in filter, limit, and track methods, which can be expensive for large Table objects and is unnecessary for shallow state changes.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/tables.py, lines 55-56, the use of `copy.deepcopy(self)` in the `filter` method is inefficient and can cause significant performance overhead for large Table objects. Replace it with a shallow copy approach that only copies the necessary attributes. Apply the same pattern to the `limit` and `track` methods.

mindsdb_sdk/utils/sql.py (1)

5-13: dict_to_binary_op does not handle empty filters dict, returning None instead of a valid AST node, which may cause downstream failures if a where clause is expected.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 5/5
  • Urgency Impact: 3/5
  • Total Score: 12/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/utils/sql.py, lines 5-13, the function `dict_to_binary_op` returns `None` when the `filters` dict is empty, which can cause downstream errors if a valid AST node is expected. Update the function so that if `filters` is empty, it returns `Constant(True)` instead of `None`, ensuring a valid AST node is always returned.

mindsdb_sdk/views.py (1)

78-80: Views._list_views assumes self.api.objects_tree(self.project.name) always returns a DataFrame with a 'type' column, which may cause runtime errors if the API response format changes or is empty.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 2/5
  • Urgency Impact: 3/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb_sdk/views.py, lines 78-80, the method `_list_views` assumes that `self.api.objects_tree(self.project.name)` always returns a DataFrame with a 'type' column. This can cause runtime errors if the API response format changes or is empty. Please update the method to check for the presence of the 'type' column before filtering, and return an empty list if it is missing.

🔍 Comments beyond diff scope (2)
mindsdb_sdk/server.py (1)

33-33: super().__init__(self, api, 'mindsdb') passes self as the first argument, which is incorrect and can cause runtime errors or unexpected behavior in the class hierarchy.
Category: correctness


mindsdb_sdk/tables.py (1)

140-140: insert method constructs a tuple instead of a string for SQL when inserting from a Query without a database, causing runtime errors when executing the query.
Category: correctness


@MinuraPunchihewa MinuraPunchihewa merged commit 3f781f2 into main Sep 1, 2025
6 checks passed
@MinuraPunchihewa MinuraPunchihewa deleted the add-tree-api branch September 1, 2025 10:21
@github-actions github-actions bot locked and limited conversation to collaborators Sep 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants