Skip to content

Commit f65d52b

Browse files
committed
RPS-6454. Python API SDK stack overflow on parsing error message
1 parent 05bab28 commit f65d52b

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Dec 09, 2022 - 3.1.5
2+
- fix of ApiResponse get attribute may cause stack overflow on requesting non-existng attribute
3+
14
May 24, 2022 - 3.1.4
25
- old tests updated to handle 423 errors for FilesAPI
36

smartlingApiSdk/ApiResponse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def __init__(self, responseString, statusCode, headers):
4242
self.isApiResonse = self.responseDict.get('response', None) and dict == type(self.responseDict['response'])
4343
self.headers = headers
4444
if self.isApiResonse:
45-
self.parseResponse(responseString)
45+
self.parseResponse()
4646

47-
def parseResponse(self, responseString):
47+
def parseResponse(self):
4848
""" parses json and fills object attributes according json attributes """
4949

5050
for k, v in list(self.responseDict['response'].items()):
@@ -59,9 +59,9 @@ def __getattr__(self, key):
5959
return getattr(self.responseDict, key)
6060

6161
try:
62-
return getattr(self, key)
62+
return self.__dict__[key]
6363
except:
64-
pass
64+
raise AttributeError("ApiResponse has no attribute %r" % ( key ))
6565

6666
def __str__(self):
6767
return str(self.responseString)

smartlingApiSdk/version.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
3-
4-
5-
""" Copyright 2012-2021 Smartling, Inc.
6-
*
7-
* Licensed under the Apache License, Version 2.0 (the "License");
8-
* you may not use this work except in compliance with the License.
9-
* You may obtain a copy of the License in the LICENSE file, or at:
10-
*
11-
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
13-
* Unless required by applicable law or agreed to in writing, software
14-
* distributed under the License is distributed on an "AS IS" BASIS,
15-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
* See the License for the specific language governing permissions and
17-
* limitations under the License.
18-
"""
19-
20-
version = "3.1.4"
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
5+
""" Copyright 2012-2021 Smartling, Inc.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this work except in compliance with the License.
9+
* You may obtain a copy of the License in the LICENSE file, or at:
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
"""
19+
20+
version = "3.1.5"

test/test_ApiResponse.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ def test_ApiResponse_status(self):
4848
assert_equal(ar.data.fileUri, 'javaUTF16.properties')
4949
assert_equal(ar.data.completedStringCount, 0)
5050
assert_equal(ar.data.callbackUrl, 'http://yourdomain.com/callback')
51+
52+
def test_ApiResponse_failed(self):
53+
failed_json = '{"response":{"code":"VALIDATION_ERROR","errors":[{"key":null,"message":"File not found: test_import.xml_2.2.4_1629202583.584802","details":null}]}}'
54+
ar = ApiResponse(failed_json, "404", {"Content-Type":"application-json"})
55+
try:
56+
ua = ar.unexisting
57+
except AttributeError as e:
58+
assert_equal(str(e), "ApiResponse has no attribute 'unexisting'")
59+
assert_equal(ar.code, "VALIDATION_ERROR")

0 commit comments

Comments
 (0)