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

[DPG] Can't generate with @pagedResult models #2914

Open
catalinaperalta opened this issue Nov 12, 2024 · 2 comments
Open

[DPG] Can't generate with @pagedResult models #2914

catalinaperalta opened this issue Nov 12, 2024 · 2 comments
Assignees

Comments

@catalinaperalta
Copy link
Member

I have the following typespec specification: https://github.com/Azure/azure-rest-api-specs/tree/feature/blob-tsp/specification/storage/Microsoft.BlobStorage

When I try to generate using the typespec-python emitter, I get the following error:

NOTE: I still see this issue with typespec-python 0.36.1.

PS C:\Users\caperal\repos\azure-rest-api-specs\specification\storage\Microsoft.BlobStorage> tsp compile .\client.tsp --emit @azure-tools/typespec-python
TypeSpec compiler v0.61.2

Traceback (most recent call last):
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python/eng/scripts/setup/run_tsp.py", line 40, in <module>
    preprocess.PreProcessPlugin(output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args).process()
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\__init__.py", line 93, in process
    self.update_yaml(yaml_data)
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\preprocess\__init__.py", line 503, in update_yaml
    self.update_operation_groups(yaml_data, client)
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\preprocess\__init__.py", line 492, in update_operation_groups
    self.get_operation_updater(operation)(code_model, operation)
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\preprocess\__init__.py", line 461, in update_paging_operation
    item_type = item_type or yaml_data["itemType"]["elementType"]
                             ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'elementType'
Emitter "@azure-tools/typespec-python" crashed! This is a bug.
Please file an issue at https://github.com/Azure/autorest.python/issues

Error: Command failed: C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\venv\Scripts\python.exe C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python/eng/scripts/setup/run_tsp.py --output-folder=C:/Users/caperal/repos/azure-rest-api-specs/specification/storage/Microsoft.BlobStorage/tsp-output/@azure-tools/typespec-python --cadl-file=C:/Users/caperal/AppData/Local/Temp/cadl-codegen/python-yaml-pathd263dee7-3893-4099-994b-0134b88c2fc0.yaml --package-version=1.0.0b1 --generate-packaging-files=true --flavor=azure --package-dir=azure-storage-blob --package-name=azure-storage-blob --package-mode=azure-dataplane --models-mode=dpg --emit-cross-language-definition-file=true --from-typespec=true
Traceback (most recent call last):
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python/eng/scripts/setup/run_tsp.py", line 40, in <module>
    preprocess.PreProcessPlugin(output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args).process()        
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\__init__.py", line 93, in process
    self.update_yaml(yaml_data)
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\preprocess\__init__.py", line 503, in update_yaml
    self.update_operation_groups(yaml_data, client)
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\preprocess\__init__.py", line 492, in update_operation_groups
    self.get_operation_updater(operation)(code_model, operation)
  File "C:\Users\caperal\repos\azure-rest-api-specs\node_modules\@typespec\http-client-python\generator\pygen\preprocess\__init__.py", line 461, in update_paging_operation
    item_type = item_type or yaml_data["itemType"]["elementType"]
                             ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'elementType'

    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at $onEmit (file:///C:/Users/caperal/repos/azure-rest-api-specs/node_modules/@typespec/http-client-python/dist/emitter/emitter.js:101:9)
    at async Object.$onEmit [as emitFunction] (file:///C:/Users/caperal/repos/azure-rest-api-specs/node_modules/@azure-tools/typespec-python/dist/src/emitter.js:3:5)
    at async runEmitter (file:///C:/Users/caperal/repos/azure-rest-api-specs/node_modules/@typespec/compiler/dist/src/core/program.js:367:13)
    at async compile (file:///C:/Users/caperal/repos/azure-rest-api-specs/node_modules/@typespec/compiler/dist/src/core/program.js:119:9)
    at async compileOnce (file:///C:/Users/caperal/repos/azure-rest-api-specs/node_modules/@typespec/compiler/dist/src/core/cli/actions/compile/compile.js:36:25)
    at async compileAction (file:///C:/Users/caperal/repos/azure-rest-api-specs/node_modules/@typespec/compiler/dist/src/core/cli/actions/compile/compile.js:19:9)

--------------------------------------------------
Library Version                0.35.1
TypeSpec Compiler Version      0.61.2
--------------------------------------------------

Workaround: Had to comment out the @pagedResult decorator in order to be able to get something generated which means the generated code is wrong.

@msyyc msyyc self-assigned this Nov 13, 2024
@msyyc
Copy link
Member

msyyc commented Nov 13, 2024

@catalinaperalta Maybe it is because you don't define Azure.Core.Items in return type of paging operation. Here is an example: https://github.com/Azure/cadl-ranch/blob/0bbcb24a30dff529be1a0bb69623237040e9d55b/packages/cadl-ranch-specs/http/azure/core/page/main.tsp#L138-L148

@catalinaperalta
Copy link
Member Author

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

No branches or pull requests

2 participants