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

Dt use patch #36977

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft

Dt use patch #36977

wants to merge 19 commits into from

Conversation

kristapratico
Copy link
Member

@kristapratico kristapratico commented Aug 21, 2024

typespec client.tsp changes: Azure/azure-rest-api-specs#30416

@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-ai-translation-document

Copy link
Member

@catalinaperalta catalinaperalta left a comment

Choose a reason for hiding this comment

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

@kristapratico can you open a draft pr for your typespec changes as well? I had a few comments about the changes.

@distributed_trace
def get_document_status(self, translation_id: str, document_id: str, **kwargs: Any) -> DocumentStatus:
def get_document_status( # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Does the generated client expose this method? And if so, do we still need to patch it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We decided to rename the parameter id to translation_id in the GA version. I was told that with the way that id is defined in the typespec, it does not allow us to rename it in the client.tsp.

tsp: https://github.com/Azure/azure-rest-api-specs/blob/8c00db9158d76c20e2d4d88c5bf0d0e72218dbe5/specification/translation/Azure.AI.DocumentTranslation/routes.tsp#L213

The following did not work:

@@clientName(DocumentTranslationClient.getDocumentStatus::parameters.id,
  "translation_id",
  "python"
);

Let me know if you know a way! Would be great to not have to patch this, too.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see...yes that is an unfortunate limitation we've been dealing with, but since I think it's more noise to patch in a client library instead of just using the @clientName decorator, I'd say just use the decorator over the typespec property inline in the code. And make sure to specify Python if it's the only language that renamed it.

@distributed_trace_async
async def get_translation_status(self, translation_id: str, **kwargs: Any) -> TranslationStatus:
async def get_translation_status(self, translation_id: str, **kwargs: Any) -> TranslationStatus: # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Could we specify the type suppression? I'm guessing it has something to do with the method signature differing from the inherited method.

Suggested change
async def get_translation_status(self, translation_id: str, **kwargs: Any) -> TranslationStatus: # type: ignore
async def get_translation_status(self, translation_id: str, **kwargs: Any) -> TranslationStatus: # type: ignore[...]

Copy link
Member Author

Choose a reason for hiding this comment

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

Your guess is correct - I will add the error type for all instances.

@@ -30,9 +30,9 @@ class Status(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Succeeded"""
FAILED = "Failed"
"""Failed"""
CANCELLED = "Cancelled"
CANCELED = "Cancelled"
Copy link
Member

Choose a reason for hiding this comment

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

Any reason we changed this? (Assuming it was public. If it's not public I guess it doesn't matter so much....)

Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't expose this in the GA version, nor the last beta. It is public by default for the current version that leverages the codegen models.

The reason I renamed the statuses here was to have consistency throughout the library. In the GA version, we decided we were against "cancelled" with a double l (don't ask me why, I don't remember 😆) and have a conversion function that changes any double l cancel to a single l in the response.

@@ -463,8 +463,8 @@ def callback(request):
assert input.source.filter.prefix == ""
assert input.source.filter.suffix == ".txt"
assert input.storage_type == "File"
assert input.targets[0].category == "fake"
assert input.targets[0].glossaries[0].format == "txt"
assert input.targets[0].category_id == "fake"
Copy link
Member

Choose a reason for hiding this comment

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

These two attributes here are breaking API changes?

Copy link
Member

Choose a reason for hiding this comment

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

Actually it seems in the APIview diff that these two properties were always called category_id and file_format?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry it's a bit confusing - we renamed a lot of things in the GA version of this library. StartTranslationDetails (the type we're accessing here) was not exposed in the GA library. We didn't expose this in the beta release following the GA either, but it was used here in a test to verify deserialization.

In this PR, we make StartTranslationDetails public, as another input option to begin_translation. To be consistent with the renaming we did in the GA library, I've renamed these two properties to match.

from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
from ._models import DocumentTranslationFileFormat
from ._patch import TranslationGlossary
Copy link
Member

Choose a reason for hiding this comment

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

Has this been manually edited?

"""Storage Source. \"AzureBlob\""""

@overload
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

This overload shouldn't be needed.


def convert_status(status, ll=False):
if ll is False:
if status == "Cancelled":
Copy link
Member

Choose a reason for hiding this comment

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

We could probably make these checks case insensitive:
if status.lower() == 'cancelled'

"""Storage Source. \"AzureBlob\""""

@overload
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

I think this overload isn't needed.

@@ -360,152 +508,207 @@ class StatusSummary(_model_base.Model):
"""Number of in progress. Required."""
not_yet_started: int = rest_field(name="notYetStarted")
"""Count of not yet started. Required."""
cancelled: int = rest_field()
canceled: int = rest_field(name="cancelled")
Copy link
Member

Choose a reason for hiding this comment

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

We don't rename body parameters. Why was this changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants