Skip to content

[http-client-python] AttributeError: 'int' object has no attribute 'rstrip' in preprocess update_description #11138

Closed

Description

@msyyc

Emitter version

@typespec/http-client-python 0.34.0

Error stack

========================================= error stack start ================================================
Error: Command failed: C:\dev\typespec\packages\http-client-python\venv\Scripts\python.exe C:\dev\typespec\packages\http-client-python/eng/scripts/setup/run_tsp.py --package-version=1.0.0b1 --generate-packaging-files=true --validate-versioning=true --clear-output-folder=false --flavor=azure --package-name=myservice --package-mode=azure-dataplane --keep-setup-py=false --from-typespec=true --models-mode=dpg --output-folder=C:/dev/typespec/packages/http-client-python/alpha/tsp-output/@typespec/http-client-python --tsp-file=C:/Users/YUCHAO~1/AppData/Local/Temp/tsp-codegen/python-yaml-pathbcbded35-4d27-48c3-99af-e63dd41aa35c.yaml
Traceback (most recent call last):
  File "C:\dev\typespec\packages\http-client-python/eng/scripts/setup/run_tsp.py", line 39, in <module>
    preprocess.PreProcessPlugin(output_folder=args.output_folder, tsp_file=args.tsp_file, **unknown_args).process()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\dev\typespec\packages\http-client-python\generator\pygen\__init__.py", line 303, in process
    self.update_yaml(yaml_data)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\dev\typespec\packages\http-client-python\generator\pygen\preprocess\__init__.py", line 706, in update_yaml
    self.update_types(yaml_data["types"])
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\typespec\packages\http-client-python\generator\pygen\preprocess\__init__.py", line 459, in update_types
    type["description"] = update_description(type.get("description", ""), type["name"])
                          ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\typespec\packages\http-client-python\generator\pygen\preprocess\__init__.py", line 113, in update_description
    description.rstrip(" ")
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'rstrip'

    at genericNodeError (node:internal/errors:985:15)
    at wrappedFn (node:internal/errors:539:14)
    at checkExecSyncError (node:child_process:925:11)
    at execSync (node:child_process:997:15)
    at runNodeEmit (file:///C:/dev/typespec/packages/http-client-python/emitter/src/node-runner.ts:112:3)
    at onEmitMain (file:///C:/dev/typespec/packages/http-client-python/emitter/src/emitter.ts:258:5)
    at Object.$onEmit [as emitFunction] (file:///C:/dev/typespec/packages/http-client-python/emitter/src/emitter.ts:170:5)
    at runEmitter (file:///C:/dev/typespec/packages/http-client-python/node_modules/@typespec/compiler/src/core/program.ts:1007:5)
    at file:///C:/dev/typespec/packages/http-client-python/node_modules/@typespec/compiler/src/core/program.ts:979:33
    at trackAction (file:///C:/dev/typespec/packages/http-client-python/node_modules/@typespec/compiler/src/core/logger/console-sink.ts:188:20)
========================================= error stack end ================================================

Reproduce

import "@typespec/http";

using TypeSpec.Http;

@service(#{ title: "My Service" })
namespace MyService;

union ApiVersion {
  string;
  `2020-01-01`: "2020-01-01";
  `2021-01-01`: "2021-01-01";
}

model Widget {
  id: string;
  name: string;
  apiVersion: ApiVersion;
}

@route("/widgets")
interface Widgets {
  @get list(): Widget[];
  @get read(@path id: string): Widget;
  @post create(@body widget: Widget): Widget;
}

Running tsp compile . --emit @typespec/http-client-python could reproduce up error.

Activity

  1. github-actions commented on Jul 2, 2026

    @github-actions
    Contributor

    🎯 Issue Triage

    The Python emitter crashes with AttributeError: 'int' object has no attribute 'rstrip' when update_description receives a non-string (integer) description value from the code model. The issue includes a clear root cause analysis and a suggested fix.

    Category: Bug
    Area: emitter:client:python

    🔁 Possible duplicate of #11137 — Issue #11137 was filed 6 seconds earlier by the same author with an identical title and body, describing the exact same bug. One of these should be closed.

    ⚠️ No reproduction provided. A minimal TypeSpec repro (e.g., a model with a numeric @doc value) would help confirm and diagnose the issue.

    🔍 Analysis
    • Affected file: generator/pygen/preprocess/__init__.py, update_description() (line ~113)
    • Version: @typespec/http-client-python 0.34.0
    • Root cause: A non-zero integer description is truthy, so it bypasses the if not description guard and hits .rstrip(" "), which doesn't exist on int. There is also a latent bug: the .rstrip() call discards its return value (no assignment), so trailing-space stripping never actually applies even for valid strings.
    • Suggested fix (from reporter): Add isinstance(description, str) to the guard, and assign the rstrip result back.
    📝 Suggested next steps

    Generated by Agentic Triage

  2. lirenhe commented on Jul 16, 2026

    @lirenhe
    Member

    close it as completed.

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

Metadata

Metadata

Labels

bugSomething isn't workingemitter:client:pythonIssue for the Python client emitter: @typespec/http-client-python

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions