Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upsert minds/datasources #44

Merged
merged 4 commits into from
Oct 29, 2024
Merged

Upsert minds/datasources #44

merged 4 commits into from
Oct 29, 2024

Conversation

ea-rus
Copy link
Contributor

@ea-rus ea-rus commented Oct 21, 2024

Added update parameter for minds.create and datasources.create.
If it is set: mind or datasource will be updated if it is exist

datasource = client.datasources.create(example_ds, update=True)

mind = client.minds.create(mind_name, update=True)

Dependent on https://github.com/mindsdb/mindsdb_gateway/pull/956

@ea-rus ea-rus requested a review from StpMax October 21, 2024 10:35
class Datasources:
def __init__(self, client):
self.api = client.api

def create(self, ds_config: DatabaseConfig, replace=False):
def create(self, ds_config: DatabaseConfig, replace=False, update=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the word 'replace' here. Without code inspection i can't predict what would happen if set this option to 'true'. For example, if i have mind 'X' with attached datasource 'Y', and then call datasource.create('Y', replace=True), then datasource 'Y' will be detached from mind 'X'. It does't look like 'replace'.
The presence of two options 'replace' and 'update' also make behavior undefined. What if i set both to 'true'?
Better will be to split this into two methods without 'replace' or 'update' arguments:

  • create - raise error if ds exists
  • upsert - update if exists, create otherwise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove 'replace' parameter

@@ -53,6 +53,16 @@ def post(self, url, data):
_raise_for_status(resp)
return resp

def put(self, url, data):
resp = requests.put(
self.base_url + url,
Copy link
Contributor

Choose a reason for hiding this comment

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

safer to use urllib.parse.urljoin

@ea-rus ea-rus merged commit 68b979a into main Oct 29, 2024
5 checks passed
@mindsdb mindsdb locked and limited conversation to collaborators Oct 29, 2024
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.

2 participants