Comment 18 for bug 1580728

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.log (master)

Reviewed: https://review.openstack.org/462735
Committed: https://git.openstack.org/cgit/openstack/oslo.log/commit/?id=72e5c3c1e258589957011506c36dd8af0a481513
Submitter: Jenkins
Branch: master

commit 72e5c3c1e258589957011506c36dd8af0a481513
Author: melanie witt <email address hidden>
Date: Thu May 4 20:22:47 2017 +0000

    Use dict arg values for unicode checks in ContextFormatter

    In ContextFormatter.format(), for python2 it checks each arg to
    determine whether unicode should be used for the format message.
    The problem is the code assumes the args are a list, when they can
    also be a dict, for example:

      LOG.info('%(thing)s', {'thing': '...'})

    and in that case, the dict keys were implicitly being used for the
    checks. The checks will always pass on string dict keys, so the
    format message gets converted to unicode even though the corresponding
    args will ultimately fail decoding to unicode. Then, the logging fails
    with:

      UnicodeDecodeError: 'ascii' codec can't decode byte 0xc6 in
      position 0: ordinal not in range(128)

    when the unicode format message causes an implicit conversion attempt
    of the args to unicode [1].

    This adds a check for the args type and uses the dict values for the
    unicode checks so that dict args with values that fail decoding will
    have: should_use_unicode = False.

    Closes-Bug: #1580728

    [1] https://github.com/python/cpython/blob/2e576f5/Lib/logging/__init__.py#L338

    Change-Id: I8c479e507efcf8acd3e3faa4a702fa6e1f18772f