Skip to content

[BUG] - Hubspot Handler - CRUD operations #11874

Merged
setohe0909 merged 8 commits into
developfrom
hubspot-handler-fixes
Nov 12, 2025
Merged

[BUG] - Hubspot Handler - CRUD operations #11874
setohe0909 merged 8 commits into
developfrom
hubspot-handler-fixes

Conversation

@setohe0909

@setohe0909 setohe0909 commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

Description

  • Fixed HubSpot table handlers so SELECT/UPDATE/DELETE filter against our exposed columns instead of fetching everything.
  • Added explicit property requests and HubSpot Search API usage so inserts/updates show up immediately in SELECT queries.

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

Verification Process

To ensure the changes are working as expected:

  • Test Location: Specify the URL or path for testing.
  • Verification Steps: Outline the steps or queries needed to validate the change. Include any data, configurations, or actions required to reproduce or see the new functionality.

Checklist:

  • My code follows the style guidelines(PEP 8) of MindsDB.
  • I have appropriately commented on my code, especially in complex areas.
  • Necessary documentation updates are either made or tracked in issues.
  • Relevant unit and integration tests are updated or added.

@setohe0909
setohe0909 requested a review from a team as a code owner November 12, 2025 00:07
@setohe0909
setohe0909 changed the base branch from main to develop November 12, 2025 00:07
@setohe0909 setohe0909 changed the title Hubspot handler CRUD operations Hubspot Handler - CRUD operations Nov 12, 2025
@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

🔒 Entelligence AI Vulnerability Scanner

No security vulnerabilities found!

Your code passed our comprehensive security analysis.

📊 Files Analyzed: 1 files


@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

Review Summary

🏷️ Draft Comments (2)

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

mindsdb/api/executor/sql_query/steps/insert_step.py (2)

117-117: dn can be None if the integration/database does not exist, leading to an AttributeError when calling dn.create_table.

📊 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/api/executor/sql_query/steps/insert_step.py, at line 117, the code assigns `dn = self.session.datahub.get(integration_name)` but does not check if `dn` is None before using it. This can cause an AttributeError if the integration/database does not exist. Please add a check after this line to raise `EntityNotExistsError` if `dn` is None, matching the pattern used elsewhere in the file.

16-99: The call method in InsertToTableCall is excessively complex (21 branches, 51 statements), making it hard to maintain and error-prone for future performance optimizations.

📊 Impact Scores:

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

🤖 AI Agent Prompt (Copy & Paste Ready):

Refactor the `call` method in the `InsertToTableCall` class (mindsdb/api/executor/sql_query/steps/insert_step.py, lines 16-99) to reduce its cyclomatic complexity and number of statements. The method currently has 21 branches and 51 statements, making it difficult to maintain and optimize. Break it into smaller, well-named helper methods for each logical section (e.g., data preparation, column filtering, duplicate removal) while preserving all existing logic and functionality.

@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

Review Summary

🏷️ Draft Comments (3)

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

mindsdb/integrations/handlers/hubspot_handler/hubspot_tables.py (3)

167-179: get_companies uses company.properties["createdate"] and company.properties["hs_lastmodifieddate"] without default values, causing KeyError if these fields are missing.

📊 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/integrations/handlers/hubspot_handler/hubspot_tables.py, lines 167-179, the code accesses `company.properties["createdate"]` and `company.properties["hs_lastmodifieddate"]` directly, which will raise a KeyError if these fields are missing. Change these to use `.get("createdate", None)` and `.get("hs_lastmodifieddate", None)` to prevent runtime exceptions.

280-283: In ContactsTable.insert, supported_columns contains duplicate 'firstname', which can cause incorrect parsing or data loss.

📊 Impact Scores:

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

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb/integrations/handlers/hubspot_handler/hubspot_tables.py, lines 280-283, the `supported_columns` list in `ContactsTable.insert` contains 'firstname' twice. Remove the duplicate to prevent incorrect parsing or data loss.

308-347: Repeated in-memory filtering of all contacts for UPDATE and DELETE operations leads to O(N) memory and API usage; should push WHERE conditions to HubSpot search API.

📊 Impact Scores:

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

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb/integrations/handlers/hubspot_handler/hubspot_tables.py lines 308-347, optimize UPDATE and DELETE operations for ContactsTable: currently, all contacts are fetched and filtered in-memory, which is inefficient for large datasets. Refactor to pass `where_conditions` to `get_contacts`, so that filtering is pushed to the HubSpot API when possible, reducing memory and API usage. Maintain original formatting.

@setohe0909
setohe0909 requested a review from sejubar November 12, 2025 00:49
@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

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/integrations/handlers/hubspot_handler/hubspot_tables.py (1)

121-129, 152-160, 308-313, 340-346, 495-503, 526-534: update and delete methods for Companies, Contacts, and Deals fetch all records with get_*() and filter in-memory, causing O(n) API calls and memory use for large datasets.

📊 Impact Scores:

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

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize the `update` and `delete` methods in `mindsdb/integrations/handlers/hubspot_handler/hubspot_tables.py` (lines 121-129, 152-160, 308-313, 340-346, 495-503, 526-534). Currently, these methods fetch all records and filter in-memory, which is highly inefficient for large datasets. Refactor to push filtering into the HubSpot API (e.g., using the Search API) so only matching records are retrieved and updated/deleted, minimizing memory and API usage. Implement helper methods like `search_company_ids(where_conditions)` to fetch only relevant IDs.

@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

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/integrations/handlers/hubspot_handler/hubspot_tables.py (1)

121-130,308-317,495-504: get_companies, get_contacts, and get_deals fetch all records and filter in-memory, causing O(n) API calls and memory use for UPDATE/DELETE on large datasets.

📊 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/integrations/handlers/hubspot_handler/hubspot_tables.py, lines 121-130, 308-317, and 495-504, the update and delete methods for CompaniesTable, ContactsTable, and DealsTable fetch all records from HubSpot and filter them in-memory to determine which records to update or delete. This results in O(n) API calls and high memory usage for large datasets, significantly degrading performance and scalability. Refactor these methods to push filtering logic into the HubSpot API by constructing appropriate filter parameters, so only relevant records are fetched and processed. Ensure the new implementation maintains functional equivalence and handles all supported query conditions.

Comment thread mindsdb/integrations/handlers/hubspot_handler/hubspot_tables.py Outdated
@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

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/integrations/handlers/hubspot_handler/hubspot_tables.py (1)

539-555: get_deals fetches all deals and processes them in Python, filtering after retrieval, causing O(n) memory/CPU and slowdowns for large datasets; this should leverage HubSpot's API filtering and pagination to minimize data transfer and processing.

📊 Impact Scores:

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

🤖 AI Agent Prompt (Copy & Paste Ready):

Optimize performance in mindsdb/integrations/handlers/hubspot_handler/hubspot_tables.py lines 539-555: The current `get_deals` implementation fetches all deals and processes them in Python, which is inefficient for large datasets. Refactor this function to use HubSpot's search API with server-side filtering, pagination, and property selection to minimize memory/CPU usage and data transfer. Ensure the function supports filters, property selection, and limit, and returns the same structure as before.

@setohe0909 setohe0909 changed the title Hubspot Handler - CRUD operations [BUG] - Hubspot Handler - CRUD operations Nov 12, 2025
@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

Review Summary

🏷️ Draft Comments (2)

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

mindsdb/integrations/handlers/mssql_handler/mssql_handler.py (2)

59-152: _make_table_response is a large, complex function (22 branches, 61 statements) that is difficult to maintain and optimize, increasing risk of subtle performance bugs and maintainability debt.

📊 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 the function `_make_table_response` in mindsdb/integrations/handlers/mssql_handler/mssql_handler.py (lines 59-152). The function is overly complex (22 branches, 61 statements), making it hard to maintain and optimize. Split the logic into smaller helper functions for type inference and DataFrame construction, and reduce cyclomatic complexity while preserving all functionality and exact output. Ensure the refactored code is functionally equivalent and easier to maintain.

430-448: table_name is interpolated directly into SQL in get_columns, allowing SQL injection if untrusted input is passed, leading to data exfiltration or modification.

📊 Impact Scores:

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

🤖 AI Agent Prompt (Copy & Paste Ready):

In mindsdb/integrations/handlers/mssql_handler/mssql_handler.py, lines 430-448, the `get_columns` method constructs a SQL query by directly interpolating `table_name` into the query string, which allows SQL injection if untrusted input is passed. Refactor this code to use a parameterized query (using `?` for pyodbc or `%s` for pymssql) and pass `table_name` as a parameter to prevent SQL injection. Ensure the fix works for both ODBC and pymssql connections.

@setohe0909
setohe0909 merged commit a4bc712 into develop Nov 12, 2025
23 checks passed
@setohe0909
setohe0909 deleted the hubspot-handler-fixes branch November 12, 2025 15:50
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2025
@setohe0909
setohe0909 restored the hubspot-handler-fixes branch November 12, 2025 16:42
@setohe0909
setohe0909 deleted the hubspot-handler-fixes branch November 12, 2025 17:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants