Description
Migrated issue, originally created by Anonymous
Percent characters in the message string constructed in orm.Mapper._log are not escaped.
In 0.6.7, a mapper based on an alias construct can have something like self.local_table.description == '%(146396108 anon)s' . This is annoying because the logging module then catches the exception and only logs a message with no reference to the source outside the logging module itself:
Traceback (most recent call last):
File "/usr/lib/python2.6/logging/handlers.py", line 71, in emit
if self.shouldRollover(record):
File "/usr/lib/python2.6/logging/handlers.py", line 144, in shouldRollover
msg = "%s\n" % self.format(record)
File "/usr/lib/python2.6/logging/init.py", line 648, in format
return fmt.format(record)
File "/usr/lib/python2.6/logging/init.py", line 436, in format
record.message = record.getMessage()
File "/usr/lib/python2.6/logging/init.py", line 306, in getMessage
msg = msg % self.args
TypeError: format requires a mapping
Proposed fix:
def _log(self, msg, *args):
self.logger.info(
"(" + self.class_.__name__ +
"|" +
(self.local_table is not None and
self.local_table.description or
str(self.local_table)) +
(self.non_primary and "|non-primary" or "") + ") " +
msg, *args)
--->
msg0 = "(" + self.class_.__name__ + "|" +
(self.local_table is not None and
self.local_table.description or
str(self.local_table)) +
(self.non_primary and "|non-primary" or "") + ") "
self.logger.info(msg0.replace('%', '%%') + msg, *args)
Activity
sqlalchemy-bot commentedon May 20, 2011
Michael Bayer (@zzzeek) wrote:
logging unfortuantely applies the "%" operator inconsistently based on if args is empty or not, so a more generalized solution ensures that all literals are passed as *args to
log.info()
andlog.debug()
.a1a588f
aa5ca4a
needless DEBUG from those commits removed in
16fc85c
ba30ce5
sqlalchemy-bot commentedon May 20, 2011
Changes by Michael Bayer (@zzzeek):