Azure / autorest.python

Extension for AutoRest (https://github.com/Azure/autorest) that generates Python code
MIT License
78 stars 57 forks source link

Incorrect type hint when generating LRO from typespec #2701

Open catalinaperalta opened 1 month ago

catalinaperalta commented 1 month ago

typespec-python: 0.25.0

The health insights service defined an LRO in the following way in tsp: https://github.com/Azure/azure-rest-api-specs/blob/5046b2ea8ec0a7701990de74feee1d357114ca7a/specification/ai/HealthInsights/HealthInsights.RadiologyInsights/route.radiologyinsights.tsp#L25

This definition is an acceptable representation of service behavior in tsp (confirmed with @johanste ). However, our internal LRO code is a bit smarter and tries to return the content of the result property of the response envelope. This behavior is ok for client libraries, however we need to make sure we're returning the correct type hint in the method signature when we do this, so we don't run into typing checking bugs.

Current method signature:

def begin_infer_radiology_insights(
        self,
        id: str,
        resource: _models.RadiologyInsightsJob,
        *,
        expand: Optional[List[str]] = None,
        content_type: str = "application/json",
        **kwargs: Any
    ) -> LROPoller[_models.RadiologyInsightsJob]:

Expected method signature:

def begin_infer_radiology_insights(
        self,
        id: str,
        resource: _models.RadiologyInsightsJob,
        *,
        expand: Optional[List[str]] = None,
        content_type: str = "application/json",
        **kwargs: Any
    ) -> LROPoller[_models.RadiologyInsightsInferenceResult]:

A related issue is allowing service partners to specify if they want the parent envelope type returned instead of the type of the result property (https://github.com/Azure/typespec-azure/issues/1167)

msyyc commented 1 month ago

It is bug of getLroMetadata in TCGC: image

the logicalResult shall be RadiologyInsightsInferenceResult instead of RadiologyInsightsJob

msyyc commented 1 month ago

It is known issue https://github.com/Azure/typespec-azure/issues/787 and before typespec-azure-core support/fix, we will have to customize it manually @catalinaperalta