Skip to content

Commit 597806e

Browse files
gbmarc1spacether
andauthored
Bug - python client deserialization when attribute named self (#9006)
* fix by mapping outside of class * tests * regeneration and tests * server * INDENT * a * enable mapping * Revert "server" This reverts commit 6fc9712fb550d258d0332df243ea5080565c6770. * Samples regenerated Co-authored-by: Justin Black <[email protected]>
1 parent cad6c16 commit 597806e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

.generator/templates/model_utils.mustache

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,11 +1283,16 @@ def get_valid_classes_phrase(input_classes):
12831283
def convert_js_args_to_python_args(fn):
12841284
from functools import wraps
12851285
@wraps(fn)
1286-
def wrapped_init(self, *args, **kwargs):
1286+
def wrapped_init(_self, *args, **kwargs):
1287+
"""
1288+
An attribute named `self` received from the api will conflicts with the reserved `self`
1289+
parameter of a class method. During generation, `self` attributes are mapped
1290+
to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
1291+
"""
12871292
spec_property_naming = kwargs.get('_spec_property_naming', False)
12881293
if spec_property_naming:
1289-
kwargs = change_keys_js_to_python(kwargs, self.__class__)
1290-
return fn(self, *args, **kwargs)
1294+
kwargs = change_keys_js_to_python(kwargs, _self.__class__)
1295+
return fn(_self, *args, **kwargs)
12911296
return wrapped_init
12921297

12931298

0 commit comments

Comments
 (0)