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

Support user dictionary loading #870

Merged
merged 4 commits into from
Oct 23, 2023

Conversation

ellnix
Copy link
Contributor

@ellnix ellnix commented Oct 23, 2023

Pull Request

Related issue

Fixes #853

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (844f540) 100.00% compared to head (52d352d) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #870   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          721       730    +9     
=========================================
+ Hits           721       730    +9     
Files Coverage Δ
meilisearch/config.py 100.00% <100.00%> (ø)
meilisearch/index.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@sanders41 sanders41 left a comment

Choose a reason for hiding this comment

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

Thanks @ellnix. Just one small change.

"""
return self.http.get(self.__settings_url_for(self.config.paths.dictionary))

def update_dictionary(self, body: Union[List[str], None]) -> TaskInfo:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Body is required here.

Suggested change
def update_dictionary(self, body: Union[List[str], None]) -> TaskInfo:
def update_dictionary(self, body: List[str]) -> TaskInfo:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I pushed this change.
Is there some reference that could have allowed me to prevent this? From what I could see most other List settings allowed None, I'm not too experienced with Python so I tried not to do my own thing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it is something that has been released like this you can find it in the API reference. In this case here. If it could be None there will be a default value, something like this.

If it is pre-release they create an issue in the integration-guide repo where you can find information about the needed changes. Something like this.

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 apologize for going on about this, but I wanted to get it straightened out before writing the text separator subroutes.

This (null update) request actually successfully clears the dictionary for a 'books' index:

curl \
  -X PUT 'http://localhost:7700/indexes/books/settings/dictionary' \ 
  -H "Content-Type: application/json" --data-binary "null"
  
{"taskUid":66184,"indexUid":"books","status":"enqueued","type":"settingsUpdate","enqueuedAt":"2023-10-24T12:09:45.811281464Z"}

That request is what would be sent since

# _http_requests.py > send_request
data=json.dumps(body) if body else "" if body == "" else "null",

represents None as null in the payload. Dictionary does in fact have a default value in the API documentation:

Reset dictionary
DELETE/indexes/{index_uid}/settings/dictionary

Reset an index's dictionary to its default value, [].

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough, I guess technically it works but it wouldn't 100% do what the user expects. [] and null aren't the same thing, so if they want to remove the values they have added they should really be using the reset route.

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 agree, reset properly communicates its intentions (or update with [] for that matter), besides a variable being unexpectedly null is a very common programming mistake which would result in clearing this whole setting.

Should we create an issue to also remove the None option for other similar settings?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In a lot of cases the None does make sense. Taking the Index create method as an example, options: Optional[Dict[str, Any]] = None makes sense because None in this case means not to attach any addtional options. In other words, some routes can take additional parameters but don't have to. So None in this case means there are no additional options to attach to the request.

In this case, even if null gets set to the server, the user is saying they want to take the defaults by not attaching additional parameters so they get what they expect.

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 suppose the distinction would be whether or not it makes sense to call the function without that argument. Index create can reasonably be called without options and use its defaults, however:

    def update_searchable_attributes(self, body: Union[List[str], None]) -> TaskInfo:

calling this method with a body of None will set searchable_attributes to all ([*]).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Your distinction is correct to me...but I found some context around why they are set like they are. #762 (comment).

So while I think the way we have gone about this PR makes the most sense to me, I suppose we should allow the None option as you originally had it to be consistant with what the team wants. Sorry about that ☹️

@ellnix
Copy link
Contributor Author

ellnix commented Oct 23, 2023

Codecov seems to be broken again

Copy link
Collaborator

@sanders41 sanders41 left a comment

Choose a reason for hiding this comment

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

Codecov seems to be broken again

Yes, I re-ran and that fixed it. Thanks for this PR!

@sanders41
Copy link
Collaborator

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Oct 23, 2023

@meili-bors meili-bors bot merged commit 8d8b4ad into meilisearch:main Oct 23, 2023
12 checks passed
@sanders41 sanders41 added the enhancement New feature or request label Oct 24, 2023
ellnix added a commit to ellnix/meilisearch-python that referenced this pull request Oct 24, 2023
meili-bors bot added a commit that referenced this pull request Oct 24, 2023
872: Revert dictionary parameter back to optional r=sanders41 a=ellnix

This reverts commit 52d352d. See: #870 (comment)


Co-authored-by: ellnix <103502144+ellnix@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v1.4] Support user-dictionary loading
2 participants