Type "str" test in Python2 code doesn't work as expected in Python3
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Karbor |
New
|
Undecided
|
Unassigned |
Bug Description
After upgraded to Ussuri version, we got an error:
```
[-] Creating image backup, image_id: 27ac514a-
[-] Protecting image (id: 27ac514a-
Traceback (most recent call last):
.py", line 199, in _create_backup
self.
File "/var/lib/
bank_
File "/var/lib/
context=
File "/var/lib/
context=
File "/var/lib/
value = jsonutils.
File "/var/lib/
return json.dumps(obj, default=default, **kwargs)
File "/usr/lib/
**
File "/usr/lib/
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/
return _iterencode(o, 0)
File "/var/lib/
return value.decode(
UnicodeDecodeE
```
It seems to be caused by the migration from Python2 to Python3.
In the errors above, we can see that it tried to decode some binary data (one chunk of image fetched from glance). The binary data is bytes type in Python3, but it's not unicode data.
In "karbor/
```
def update_object(self, key, value, context=None):
serialized = False
try:
if not isinstance(value, str):
except SwiftConnection
raise exception.
```
We can see that it tests if "value" is "str" type. If not, it calls jsonutils.dumps to serialize it.
In Python2, binary data is str type. But in Python3, it's "bytes" type, not "str". So in Python3, we can't test if an object is binary in this way.