-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Define match conditions for CreateOrUpdate and Delete operations #11116
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
Changes from 5 commits
60d8822
722fd37
92207f7
288b46b
96d1318
f026a13
4e01084
146b6b3
a144727
79da71a
24b2180
0a84da3
4a3e126
b0ca117
756fd7a
e8203d7
139c208
63c1328
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,14 @@ | |
|
|
||
| from ._generated import SearchServiceClient as _SearchServiceClient | ||
| from ._generated.models import Skillset | ||
| from ._utils import get_access_conditions | ||
| from .._headers_mixin import HeadersMixin | ||
| from .._version import SDK_MONIKER | ||
|
|
||
| if TYPE_CHECKING: | ||
| # pylint:disable=unused-import,ungrouped-imports | ||
| from ._generated.models import Skill | ||
| from typing import Any, List, Sequence | ||
| from typing import Any, List, Sequence, Union | ||
| from azure.core.credentials import AzureKeyCredential | ||
|
|
||
|
|
||
|
|
@@ -102,12 +103,17 @@ def get_skillset(self, name, **kwargs): | |
| return self._client.skillsets.get(name, **kwargs) | ||
|
|
||
| @distributed_trace | ||
| def delete_skillset(self, name, **kwargs): | ||
| # type: (str, **Any) -> None | ||
| """Delete a named Skillset in an Azure Search service | ||
|
|
||
| :param name: The name of the Skillset to delete | ||
| :type name: str | ||
| def delete_skillset(self, skillset, **kwargs): | ||
| # type: (Union[str, Skillset], **Any) -> None | ||
| """Delete a named Skillset in an Azure Search service. To use only_if_unchanged, | ||
| the Skillset model must be provided instead of the name. It is enough to provide | ||
| the name of the skillset to delete unconditionally | ||
|
|
||
| :param name: The Skillset to delete | ||
| :type name: str or ~search.models.Skillset | ||
| :keyword only_if_unchanged: If set to true, the operation is performed only if the | ||
| e_tag on the server matches the e_tag value of the passed skillset. | ||
| :type only_if_unchanged: bool | ||
|
|
||
| .. admonition:: Example: | ||
|
|
||
|
|
@@ -120,7 +126,13 @@ def delete_skillset(self, name, **kwargs): | |
|
|
||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| self._client.skillsets.delete(name, **kwargs) | ||
| access_condition = None | ||
| try: | ||
| name = skillset.name | ||
| access_condition = get_access_conditions(skillset, kwargs.pop('only_if_unchanged', False)) | ||
| except AttributeError: | ||
| name = skillset | ||
| self._client.skillsets.delete(name, access_condition=access_condition, **kwargs) | ||
|
|
||
| @distributed_trace | ||
| def create_skillset(self, name, skills, description, **kwargs): | ||
|
|
@@ -156,18 +168,20 @@ def create_skillset(self, name, skills, description, **kwargs): | |
| def create_or_update_skillset(self, name, **kwargs): | ||
| # type: (str, **Any) -> Skillset | ||
| """Create a new Skillset in an Azure Search service, or update an | ||
| existing one. | ||
|
|
||
| A `Skillset` object mat | ||
| existing one. The skillset param must be provided to perform the | ||
| operation with access conditions. | ||
|
|
||
| :param name: The name of the Skillset to create or update | ||
| :type name: str | ||
| :param skills: A list of Skill objects to include in the Skillset | ||
| :keyword skills: A list of Skill objects to include in the Skillset | ||
| :type skills: List[Skill] | ||
| :param description: A description for the Skillset | ||
| :keyword description: A description for the Skillset | ||
| :type description: Optional[str] | ||
| :param skillset: A Skillset to create or update. | ||
| :keyword skillset: A Skillset to create or update. | ||
| :type skillset: :class:`~azure.search.documents.Skillset` | ||
| :keyword only_if_unchanged: If set to true, the operation is performed only if the | ||
| e_tag on the server matches the e_tag value of the passed skillset. | ||
| :type only_if_unchanged: bool | ||
| :return: The created or updated Skillset | ||
| :rtype: dict | ||
|
|
||
|
|
@@ -176,9 +190,11 @@ def create_or_update_skillset(self, name, **kwargs): | |
|
|
||
| """ | ||
| kwargs["headers"] = self._merge_client_headers(kwargs.get("headers")) | ||
| access_condition = None | ||
|
|
||
| if "skillset" in kwargs: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need more consistency in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you be more specific?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will drag this discussion off the PR and send a mail about it. |
||
| skillset = kwargs.pop("skillset") | ||
| access_condition = get_access_conditions(skillset, kwargs.pop('only_if_unchanged', False)) | ||
| skillset = Skillset.deserialize(skillset.serialize()) | ||
| skillset.name = name | ||
| for param in ("description", "skills"): | ||
|
|
@@ -192,4 +208,9 @@ def create_or_update_skillset(self, name, **kwargs): | |
| skills=kwargs.pop("skills", None), | ||
| ) | ||
|
|
||
| return self._client.skillsets.create_or_update(name, skillset, **kwargs) | ||
| return self._client.skillsets.create_or_update( | ||
| skillset_name=name, | ||
| skillset=skillset, | ||
| access_condition=access_condition, | ||
| **kwargs | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.