[Bug]: http-client-python - IndexError raised if there's an empty interface

Open Beginner friendly
#7,835 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
tooling

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

bug emitter:client:python
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
Dominant language
Java
Stars
5.9k
Forks
395
Avg merge
1d 21h
Merged PRs (30d)
105

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/typespec

All issues in microsoft/typespec

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.