diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-05-20 14:43:06 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-05-20 14:43:06 -0400 |
commit | a1a588fabdf76dede32af5292535bf7dbabcc0bf (patch) | |
tree | e3d9a815123053e14172fde6ae8536dd2663cd05 | |
parent | c7713a6f0af7c76321fd5a72fbae0e8c4a52179c (diff) | |
download | sqlalchemy-a1a588fabdf76dede32af5292535bf7dbabcc0bf.tar.gz |
- Fixed bug whereby mapper mapped to an anonymous
alias would fail if logging were used, due to
unescaped % sign in the alias name. [ticket:2171]
Also in 0.6.8.
-rw-r--r-- | CHANGES | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 29 | ||||
-rw-r--r-- | test/orm/test_mapper.py | 28 |
3 files changed, 48 insertions, 14 deletions
@@ -87,6 +87,11 @@ CHANGES unions in which they appear. (which is itself an unordered mapping unless you pass an OrderedDict). + - Fixed bug whereby mapper mapped to an anonymous + alias would fail if logging were used, due to + unescaped % sign in the alias name. [ticket:2171] + Also in 0.6.8. + - sql - Fixed bug whereby nesting a label of a select() with another label in it would produce incorrect diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 53f8af0b4..a426e28ac 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1066,25 +1066,26 @@ class Mapper(object): for mapper in self.iterate_to_root(): _memoized_configured_property.expire_instance(mapper) - def _log(self, msg, *args): - self.logger.info( - "(" + self.class_.__name__ + - "|" + + @property + def _log_desc(self): + return "(" + 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) + str(self.local_table)) +\ + (self.non_primary and + "|non-primary" or "") + ")" + + def _log(self, msg, *args): + + self.logger.info( + "%s " + msg, *((self._log_desc,) + args) + ) def _log_debug(self, msg, *args): self.logger.debug( - "(" + 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) + "%s " + msg, *((self._log_desc,) + args) + ) def __repr__(self): return '<Mapper at 0x%x; %s>' % ( diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 604c92f41..f292f5e73 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -15,6 +15,7 @@ from test.lib.testing import eq_, AssertsCompiledSQL from test.lib import fixtures from test.orm import _fixtures from test.lib.assertsql import CompiledSQL +import logging class MapperTest(_fixtures.FixtureTest): @@ -1410,7 +1411,34 @@ class DocumentTest(fixtures.TestBase): eq_(Bar.col1.__doc__, "primary key column") eq_(Bar.foo.__doc__, "foo relationship") +class ORMLoggingTest(_fixtures.FixtureTest): + def setup(self): + self.buf = logging.handlers.BufferingHandler(100) + for log in [ + logging.getLogger('sqlalchemy.orm'), + ]: + log.addHandler(self.buf) + log.setLevel(logging.DEBUG) + + def teardown(self): + for log in [ + logging.getLogger('sqlalchemy.orm'), + ]: + log.removeHandler(self.buf) + + def _current_messages(self): + return [b.getMessage() for b in self.buf.buffer] + + def test_mapper_info_aliased(self): + User, users = self.classes.User, self.tables.users + tb = users.select().alias() + mapper(User, tb) + s = Session() + s.add(User(name='ed')) + s.commit() + for msg in self._current_messages(): + assert msg.startswith('(User|%%(%d anon)s) ' % id(tb)) class OptionsTest(_fixtures.FixtureTest): |