You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logging.config.dictConfig will convert namedtuple to ConvertingTuple #83323
to logging.config.dictConfig it will convert resource, which is a namedtuple to ConvertingTuple, this will make google.cloud.logging.handlers.CloudLoggingHandler break down the line.
Thanks for the report. Can you please attach a sample script with the handler used to illustrate the issue?
hcoura commented on Dec 28, 2019
hcouramannequin
MannequinAuthor
More actions
Sorry for not sending a proper reproducible script when submitting the issue. End of the day and quite frustrated with the bug, anyway, I attached a full script that will show the error.
Thanks for the details. Attached is a complete script. Looking at the source code, anything that looks like a tuple is converted into a tuple. namedtuple produces factory function that itself is a subclass of tuple. It led me to this interesting issue over detecting if it's a namedtuple bpo-7796 where detecting _fields in msg134186 is described as a workaround. So logging might detect namedtuple and skip conversion to ConvertingTuple using the workaround but it appears more of the class of special casing it here in logging that will depend on namedtuple internals. There are no test failures. I will leave it to vinay on this.
>>> import collections
>>> person = collections.namedtuple('Person', 'age')
>>> isinstance(person(age=20), tuple)
True
>>> print(person._source) # works on 3.6 but verbose and _source were removed in 3.7 with 8b57d7363916869357848e666d03fa7614c47897
from builtins import property as _property, tuple as _tuple
from operator import itemgetter as _itemgetter
from collections import OrderedDict
Activity
hcoura commentedon Dec 27, 2019
While passing
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {"format": "%(levelname)s %(asctime)s %(module)s %(message)s"}
},
"handlers": {
"stackdriver": {
"class": "google.cloud.logging.handlers.CloudLoggingHandler",
"client": client,
"resource": resource,
},
},
"root": {"level": "INFO", "handlers": ["stackdriver"]},
}
to logging.config.dictConfig it will convert resource, which is a namedtuple to ConvertingTuple, this will make google.cloud.logging.handlers.CloudLoggingHandler break down the line.
I am having to create a wrapper class like
to go around this
tirkarthi commentedon Dec 28, 2019
Thanks for the report. Can you please attach a sample script with the handler used to illustrate the issue?
hcoura commentedon Dec 28, 2019
Sorry for not sending a proper reproducible script when submitting the issue. End of the day and quite frustrated with the bug, anyway, I attached a full script that will show the error.
This is the custom handler I used:
self.resource.type will throw and AttributeError when logging, because resource gets converted from a namedtuple to a ConvertingTuple.
tirkarthi commentedon Dec 28, 2019
Thanks for the details. Attached is a complete script. Looking at the source code, anything that looks like a tuple is converted into a tuple. namedtuple produces factory function that itself is a subclass of tuple. It led me to this interesting issue over detecting if it's a namedtuple bpo-7796 where detecting _fields in msg134186 is described as a workaround. So logging might detect namedtuple and skip conversion to ConvertingTuple using the workaround but it appears more of the class of special casing it here in logging that will depend on namedtuple internals. There are no test failures. I will leave it to vinay on this.
# Detect namedtuple by checking for _fields attribute
vsajip commentedon Jan 1, 2020
New changeset 46abfc1 by Vinay Sajip in branch 'master':
bpo-39142: Avoid converting namedtuple instances to ConvertingTuple. (GH-17773)
46abfc1
vsajip commentedon Jan 1, 2020
New changeset 1d5a7e5 by Vinay Sajip (Miss Islington (bot)) in branch '3.8':
bpo-39142: Avoid converting namedtuple instances to ConvertingTuple. (GH-17773) (GH-17785)
1d5a7e5
vsajip commentedon Jan 1, 2020
New changeset 0e0e4ac by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
bpo-39142: Avoid converting namedtuple instances to ConvertingTuple. (GH-17773) (GH-17786)
0e0e4ac