diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-20 20:40:39 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-01-20 20:40:39 +0000 |
commit | 7838cb175913cc19ad3701a9de16ab16cdf0809f (patch) | |
tree | 3717518ee981b0b30b999f297430eec6de2f66c9 /lib/sqlalchemy/ext/assignmapper.py | |
parent | ceea2cf0d4c3bc56640d6e34fb6cbc86d9023be5 (diff) | |
download | sqlalchemy-7838cb175913cc19ad3701a9de16ab16cdf0809f.tar.gz |
- added "validate=False" argument to assign_mapper, if True will insure that only mapped
attributes are named [ticket:426]
Diffstat (limited to 'lib/sqlalchemy/ext/assignmapper.py')
-rw-r--r-- | lib/sqlalchemy/ext/assignmapper.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py index 8c78e7024..dddb25bdc 100644 --- a/lib/sqlalchemy/ext/assignmapper.py +++ b/lib/sqlalchemy/ext/assignmapper.py @@ -1,4 +1,4 @@ -from sqlalchemy import mapper, util, Query +from sqlalchemy import mapper, util, Query, exceptions import types def monkeypatch_query_method(ctx, class_, name): @@ -17,9 +17,13 @@ def monkeypatch_objectstore_method(ctx, class_, name): setattr(class_, name, do) 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) class_.__init__ = __init__ extension = kwargs.pop('extension', None) |