From: Jason Kirtland Date: Thu, 5 Jul 2007 23:20:04 +0000 (+0000) Subject: Fix up extensions in wake of r2852 mapper.props change X-Git-Tag: rel_0_4_6~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9211d6f2dc5d027913d1989dc1c57178511042ba;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix up extensions in wake of r2852 mapper.props change --- diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py index 2170be72fe..f78e464933 100644 --- a/lib/sqlalchemy/ext/assignmapper.py +++ b/lib/sqlalchemy/ext/assignmapper.py @@ -27,11 +27,12 @@ def assign_mapper(ctx, class_, *args, **kwargs): validate = kwargs.pop('validate', False) if not isinstance(getattr(class_, '__init__'), types.MethodType): def __init__(self, **kwargs): - for key, value in kwargs.items(): - if validate: - if not key in self.mapper.props: - raise exceptions.ArgumentError("Invalid __init__ argument: '%s'" % key) - setattr(self, key, value) + if validate: + keys = [p.key for p in self.mapper.iterate_properties] + for key, value in kwargs.items(): + if validate and key not in keys: + raise exceptions.ArgumentError("Invalid __init__ argument: '%s'" % key) + setattr(self, key, value) class_.__init__ = __init__ extension = kwargs.pop('extension', None) if extension is not None: diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 60e6dc0e48..b077a433a7 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -108,7 +108,7 @@ class AssociationProxy(object): self.collection_class = None def _get_property(self): - return orm.class_mapper(self.owning_class).props[self.target_collection] + return orm.class_mapper(self.owning_class).get_property(self.target_collection) def _target_class(self): return self._get_property().mapper.class_ diff --git a/test/ext/activemapper.py b/test/ext/activemapper.py index 78aad0c934..dd967d9ec4 100644 --- a/test/ext/activemapper.py +++ b/test/ext/activemapper.py @@ -313,8 +313,6 @@ class testmanytomany(testbase.PersistTest): # Optimistically based on activemapper one_to_many test, try to append # baz1 to foo1.bazrel - (AttributeError: 'foo' object has no attribute 'bazrel') - print class_mapper(foo).props - print class_mapper(baz).props foo1.bazrel.append(baz1) assert (foo1.bazrel == [baz1]) diff --git a/test/ext/assignmapper.py b/test/ext/assignmapper.py index c5a2d31916..17c10d3d72 100644 --- a/test/ext/assignmapper.py +++ b/test/ext/assignmapper.py @@ -45,6 +45,19 @@ class OverrideAttributesTest(PersistTest): ctx.current.clear() assert SomeObject.get_by(id=s.id).options[0].id == sso.id + + s2 = SomeObject(someid=12) + s3 = SomeOtherObject(someid=123, bogus=345) + + class ValidatedOtherObject(object):pass + assign_mapper(ctx, ValidatedOtherObject, table2, validate=True) + + v1 = ValidatedOtherObject(someid=12) + try: + v2 = ValidatedOtherObject(someid=12, bogus=345) + assert False + except exceptions.ArgumentError: + pass if __name__ == '__main__': testbase.main()