From: Jason Kirtland Date: Fri, 2 May 2008 18:47:05 +0000 (+0000) Subject: - The collection instrumentation sweep now skips over descriptors that raise Attribut... X-Git-Tag: rel_0_5beta1~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a61dfeeff3ce46c5038fe6b05eae66545a0a43e2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - The collection instrumentation sweep now skips over descriptors that raise AttributeError. --- diff --git a/CHANGES b/CHANGES index c3fa9f1fc8..35da79f4b0 100644 --- a/CHANGES +++ b/CHANGES @@ -46,9 +46,9 @@ CHANGES conflicts with a subquery or column of the same name on the parent object. [ticket:1019] - - Removed a class-member inspection step from attribute - instrumentation that could be problematic when integrating - with other frameworks. + - Adjusted class-member inspection durint attribute and + collection instrumentation that could be problematic when + integrating with other frameworks. - declarative extension - Joined table inheritance mappers use a slightly relaxed diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index 1c07fb8094..ae4cb65cde 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -750,7 +750,7 @@ def _instrument_class(cls): methods = roles.pop('methods', {}) for name in dir(cls): - method = getattr(cls, name) + method = getattr(cls, name, None) if not callable(method): continue diff --git a/test/orm/collection.py b/test/orm/collection.py index 2abec607a6..17c15876dd 100644 --- a/test/orm/collection.py +++ b/test/orm/collection.py @@ -1724,5 +1724,23 @@ class CustomCollectionsTest(ORMTest): o = list(p2.children) assert len(o) == 3 + +class InstrumentationTest(TestBase): + + def test_uncooperative_descriptor_in_sweep(self): + class DoNotTouch(object): + def __get__(self, obj, owner): + raise AttributeError + + class Touchy(list): + no_touch = DoNotTouch() + + assert 'no_touch' in Touchy.__dict__ + assert not hasattr(Touchy, 'no_touch') + assert 'no_touch' in dir(Touchy) + + instrumented = collections._instrument_class(Touchy) + assert True + if __name__ == "__main__": testenv.main()