Fix request_id type on Python 3: use text (Unicode)
generate_request_id() was previously modified by the change I389cf20e4c999c9bb576a42388497852f8ba27ec to return a bytes string instead of a text string. According to the author of the change, it was a mistake (the right fix is to update the unit test, not modify the tested function). Having a request_id as a byte string is not convenient on Python 3. For example, it's a bug to write '"id:%s" % request_id', a BytesWarning exception is raised when python3 is run with -bb command line option. It not possible to write str+bytes neither. Right now, oslo_log emits logs with b'...' which is unexpected. I prefer to fix the issue in oslo_context rather than working around the issue in oslo_log. Example of log emitted on Python 3: "WARNING glance.api.v2.tasks [b'req-83a6...' 54492... - - -] ..." This change depends on changes in Glance, Neutron and oslo.middleware which prepares unit tests to support bytes and str request_id. So their unit tests will work on the old and new versions of oslo.context. Changes on unit tests are required for the master branch but also Liberty because their python34 check job is voting on Liberty and master. This change depends on the following changes: * change Ia8578ecab1b1f1bf21020c91290458efad646cd9 * change Ia5203581db120bb4f8e24fd752d6ae14e6558505 * change I872c268ef5f17dc2c1fe0ce8aa7e8af4ebc1d757 * change Ia4df8f05d5746887eb99bbf368d29e8d30a3a90a Closes-Bug: #1526662 Change-Id: If48ee7f4d1c113f1f26b3b1698c6b055807b950f
This commit is contained in:
parent
e6dfe63641
commit
4a8a1dfbbb
|
@ -29,7 +29,7 @@ _request_store = threading.local()
|
|||
|
||||
|
||||
def generate_request_id():
|
||||
return b'req-' + str(uuid.uuid4()).encode('ascii')
|
||||
return 'req-%s' % uuid.uuid4()
|
||||
|
||||
|
||||
class RequestContext(object):
|
||||
|
|
Loading…
Reference in New Issue