Skip to content

Commit ff056eb

Browse files
iscai-msftiscai-msft
andauthored
[python] import json encoder only when needed (#5607)
fixes Azure/autorest.python#3005 --------- Co-authored-by: iscai-msft <[email protected]>
1 parent f260ff0 commit ff056eb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/http-client-python/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Bug Fixes
66

7+
- Only import helpers for serialization if input body is not binary
78
- Unify descriptions for credentials in documentation
89

910
### Other Changes

packages/http-client-python/generator/pygen/codegen/models/operation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
)
3636
from .parameter_list import ParameterList
3737
from .model_type import ModelType
38+
from .primitive_types import BinaryType
3839
from .base import BaseType
3940
from .combined_type import CombinedType
4041
from .request_builder import OverloadedRequestBuilder, RequestBuilder
@@ -432,7 +433,8 @@ def imports( # pylint: disable=too-many-branches, disable=too-many-statements
432433
file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
433434
if self.code_model.options["models_mode"] == "dpg":
434435
relative_path = self.code_model.get_relative_import_path(serialize_namespace, module_name="_model_base")
435-
if self.parameters.has_body:
436+
body_param = self.parameters.body_parameter if self.parameters.has_body else None
437+
if body_param and not isinstance(body_param.type, BinaryType):
436438
if self.has_form_data_body:
437439
file_import.add_submodule_import(
438440
self.code_model.get_relative_import_path(serialize_namespace), "_model_base", ImportType.LOCAL

0 commit comments

Comments
 (0)