Skip to content

Commit 19e1423

Browse files
[python-experimental] Add support for pep 3134, attach cause of exception (#6388)
* Mustache template should use invokerPackage tag to generate import * Add exception cause * using six module for exception chaining in Python 3.x
1 parent 912604f commit 19e1423

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,14 @@ def deserialize_primitive(data, klass, path_to_item):
725725
# '7' -> 7.0 -> '7.0' != '7'
726726
raise ValueError('This is not a float')
727727
return converted_value
728-
except (OverflowError, ValueError):
728+
except (OverflowError, ValueError) as ex:
729729
# parse can raise OverflowError
730-
raise ApiValueError(
730+
six.raise_from(ApiValueError(
731731
"{0}Failed to parse {1} as {2}".format(
732732
additional_message, repr(data), get_py3_class_name(klass)
733733
),
734734
path_to_item=path_to_item
735-
)
735+
), ex)
736736

737737

738738
def get_discriminator_class(model_class,
@@ -1220,7 +1220,7 @@ def get_allof_instances(self, model_args, constant_args):
12201220
allof_instance = allof_class(**kwargs)
12211221
composed_instances.append(allof_instance)
12221222
except Exception as ex:
1223-
raise ApiValueError(
1223+
six.raise_from(ApiValueError(
12241224
"Invalid inputs given to generate an instance of '%s'. The "
12251225
"input data was invalid for the allOf schema '%s' in the composed "
12261226
"schema '%s'. Error=%s" % (
@@ -1229,7 +1229,7 @@ def get_allof_instances(self, model_args, constant_args):
12291229
self.__class__.__name__,
12301230
str(ex)
12311231
)
1232-
)
1232+
), ex)
12331233
return composed_instances
12341234

12351235

samples/client/petstore/python-experimental/petstore_api/model_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,14 @@ def deserialize_primitive(data, klass, path_to_item):
992992
# '7' -> 7.0 -> '7.0' != '7'
993993
raise ValueError('This is not a float')
994994
return converted_value
995-
except (OverflowError, ValueError):
995+
except (OverflowError, ValueError) as ex:
996996
# parse can raise OverflowError
997-
raise ApiValueError(
997+
six.raise_from(ApiValueError(
998998
"{0}Failed to parse {1} as {2}".format(
999999
additional_message, repr(data), get_py3_class_name(klass)
10001000
),
10011001
path_to_item=path_to_item
1002-
)
1002+
), ex)
10031003

10041004

10051005
def get_discriminator_class(model_class,
@@ -1487,7 +1487,7 @@ def get_allof_instances(self, model_args, constant_args):
14871487
allof_instance = allof_class(**kwargs)
14881488
composed_instances.append(allof_instance)
14891489
except Exception as ex:
1490-
raise ApiValueError(
1490+
six.raise_from(ApiValueError(
14911491
"Invalid inputs given to generate an instance of '%s'. The "
14921492
"input data was invalid for the allOf schema '%s' in the composed "
14931493
"schema '%s'. Error=%s" % (
@@ -1496,7 +1496,7 @@ def get_allof_instances(self, model_args, constant_args):
14961496
self.__class__.__name__,
14971497
str(ex)
14981498
)
1499-
)
1499+
), ex)
15001500
return composed_instances
15011501

15021502

samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,14 @@ def deserialize_primitive(data, klass, path_to_item):
992992
# '7' -> 7.0 -> '7.0' != '7'
993993
raise ValueError('This is not a float')
994994
return converted_value
995-
except (OverflowError, ValueError):
995+
except (OverflowError, ValueError) as ex:
996996
# parse can raise OverflowError
997-
raise ApiValueError(
997+
six.raise_from(ApiValueError(
998998
"{0}Failed to parse {1} as {2}".format(
999999
additional_message, repr(data), get_py3_class_name(klass)
10001000
),
10011001
path_to_item=path_to_item
1002-
)
1002+
), ex)
10031003

10041004

10051005
def get_discriminator_class(model_class,
@@ -1487,7 +1487,7 @@ def get_allof_instances(self, model_args, constant_args):
14871487
allof_instance = allof_class(**kwargs)
14881488
composed_instances.append(allof_instance)
14891489
except Exception as ex:
1490-
raise ApiValueError(
1490+
six.raise_from(ApiValueError(
14911491
"Invalid inputs given to generate an instance of '%s'. The "
14921492
"input data was invalid for the allOf schema '%s' in the composed "
14931493
"schema '%s'. Error=%s" % (
@@ -1496,7 +1496,7 @@ def get_allof_instances(self, model_args, constant_args):
14961496
self.__class__.__name__,
14971497
str(ex)
14981498
)
1499-
)
1499+
), ex)
15001500
return composed_instances
15011501

15021502

0 commit comments

Comments
 (0)