Azure / Azure/azure-sdk-for-python

`BatchClient.begin_terminate_job` crashes with default value for option parameter

オープン
#47,201 コメント 2 件 リアクション 0 件 担当者 2 名 GitHub で見る

@msyyc がすでに取り組んでいます。

2026年7月15日 から。

Batch customer-reported needs-team-attention question Service Attention
主要言語
Python
スター
5.6k
フォーク
3.4k
平均マージ
2日 2時間
マージ済み PR(30日)
213

説明

  • Package Name: azure-batch
  • Package Version: 15.1.0
  • Operating System: Ubuntu 24.04
  • Python Version: 3.13.13

Describe the bug
BatchClient.begin_terminate_job() doesn't correctly handle the case where you call it with the default value for the options parameter. It also fails identically with a default-constructed BatchJobTerminateOptions passed to it. The stack trace is:

  File "/opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/azure/batch/_operations/_patch.py", line 1008, in begin_terminate_job
    self._terminate_job_internal(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        job_id,
        ^^^^^^^
    ...<9 lines>...
        **kwargs,
        ^^^^^^^^^
    ),
    ^
  File "/opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/azure/core/tracing/decorator.py", line 119, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/azure/batch/_operations/_operations.py", line 5806, in _terminate_job_internal
    _request = build_batch_terminate_job_internal_request(
        job_id=job_id,
    ...<11 lines>...
        params=_params,
    )
  File "/opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/azure/batch/_operations/_operations.py", line 1071, in build_batch_terminate_job_internal_request
    _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str")
                               ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/azure/batch/_utils/serialization.py", line 758, in header
    output = self.serialize_data(data, data_type, **kwargs)
  File "/opt/hostedtoolcache/Python/3.13.13/x64/lib/python3.13/site-packages/azure/batch/_utils/serialization.py", line 777, in serialize_data
    raise ValueError("No value for given attribute")
ValueError: No value for given attribute

From this we can determine what the happens to cause this bug:

  1. _terminate_job_internal only sets content_type if options is true (in the bool sense). Neither the default value (None) nor the default-constructed BatchJobTerminateOptions evaluate to true. So content_type ends up equal to None.
  2. build_batch_terminate_job_internal_request will always set the content-type header, regardless of if content-type was actually provided (_headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str")). This should be guarded by an if statement like all of the other headers are.

To Reproduce
Steps to reproduce the behavior:

  1. Call BatchClient.begin_terminate_job with the default value for options (or with a default constructed BatchJobTerminateOptions).
  2. Observe the crash above.

Expected behavior
The default value should work.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。