[Bug]: http-client-python - IndexError raised if there's an empty interface
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Reproduce the failure with the minimal TypeSpec service and empty EmployeeAPI interface shown in the issue. Read generator/pygen/codegen/models/code_model.py around client_namespace_types and generator/pygen/codegen/serializers/init.py around serialize; done means the Python client generator handles this input without the IndexError.
Written by the indexing model from the issue text.
Description
Describe the bug
If the main namespace has a empty interface, the python client generator breaks.
error @typespec/http-client-python/unknown-error: Can't generate Python client code from this TypeSpec. Please open an issue on https://github.com/microsoft/typespec'.
========================================= error stack start ================================================
Error: Command failed: <project-path>/node_modules/@typespec/http-client-python/venv/bin/python <project-path>/node_modules/@typespec/http-client-python/eng/scripts/setup/run_tsp.py --package-version=1.0.0b1 --generate-packaging-files=true --validate-versioning=true --package-name= --flavor=undefined --package-mode=azure-dataplane --from-typespec=true --models-mode=dpg --output-folder=<project-path>/tsp-output/clients/python --tsp-file=/tmp/tsp-codegen/python-yaml-pathaee28f14-570c-4e78-8acf-cdad46280460.yaml
Traceback (most recent call last):
File "<project-path>/node_modules/@typespec/http-client-python/eng/scripts/setup/run_tsp.py", line 40, in <module>
codegen.CodeGenerator(output_folder=args.output_folder, tsp_file=args.tsp_file, **unknown_args).process()
File "<project-path>/node_modules/@typespec/http-client-python/generator/pygen/codegen/__init__.py", line 84, in process
serializer.serialize()
File "<project-path>/node_modules/@typespec/http-client-python/generator/pygen/codegen/serializers/__init__.py", line 122, in serialize
for client_namespace, client_namespace_type in self.code_model.client_namespace_types.items():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<project-path>/node_modules/@typespec/http-client-python/generator/pygen/codegen/models/code_model.py", line 187, in client_namespace_types
longest_namespace = sorted(self._client_namespace_types.keys())[-1]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at checkExecSyncError (node:child_process:892:11)
at execSync (node:child_process:964:15)
at onEmitMain (file://<project-path>/node_modules/@typespec/http-client-python/dist/emitter/emitter.js:207:13)
at async Object.$onEmit [as emitFunction] (file://<project-path>/node_modules/@typespec/http-client-python/dist/emitter/emitter.js:95:9)
at async runEmitter (file://<project-path>/node_modules/@typespec/compiler/dist/src/core/program.js:711:9)
at async file://<project-path>/node_modules/@typespec/compiler/dist/src/core/program.js:684:9
at async trackAction (file://<project-path>/node_modules/@typespec/compiler/dist/src/core/logger/console-sink.js:133:24)
at async emit (file://<project-path>/node_modules/@typespec/compiler/dist/src/core/program.js:682:12)
========================================= error stack end ================================================
Found 1 error.
Reproduction
import "@typespec/http";
@service(#{ title: "Employee Management" })
namespace EmployeeManagement {
interface EmployeeAPI {}
}
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 395
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 105
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/typespec
-
bug emitter:client:python
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
emitter:client:js
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug emitter:openapi3 triaged:core
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
bug emitter:service:csharp triaged:core
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
emitter:client:java feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
All issues in microsoft/typespec
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100