From: Gaƫtan de Menten Date: Tue, 31 Jul 2007 14:54:28 +0000 (+0000) Subject: - restored old assign_mapper monkey patched query methods but with two differences: X-Git-Tag: rel_0_4beta1~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c31abf1d3bc06b6e7eba8d4bbee7569636c4a33;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - restored old assign_mapper monkey patched query methods but with two differences: * added a deprecation warning * check if a method with that name already exist in the class - more foolproof deprecation warning for scalar kwarg --- diff --git a/lib/sqlalchemy/ext/assignmapper.py b/lib/sqlalchemy/ext/assignmapper.py index 2380417020..cab5a9eae6 100644 --- a/lib/sqlalchemy/ext/assignmapper.py +++ b/lib/sqlalchemy/ext/assignmapper.py @@ -1,7 +1,19 @@ from sqlalchemy import util, exceptions import types -from sqlalchemy.orm import mapper +from sqlalchemy.orm import mapper, Query +def _monkeypatch_query_method(name, ctx, class_): + def do(self, *args, **kwargs): + query = Query(class_, session=ctx.current) + util.warn_deprecated('Query methods on the class are deprecated; use %s.query.%s instead' % (class_.__name__, name)) + return getattr(query, name)(*args, **kwargs) + try: + do.__name__ = name + except: + pass + if not hasattr(class_, name): + setattr(class_, name, classmethod(do)) + def _monkeypatch_session_method(name, ctx, class_): def do(self, *args, **kwargs): session = ctx.current @@ -41,7 +53,9 @@ def assign_mapper(ctx, class_, *args, **kwargs): if not hasattr(class_, 'query'): class_.query = query() - for name in ['refresh', 'expire', 'delete', 'expunge', 'update']: + for name in ('get', 'filter', 'filter_by', 'select', 'select_by', 'selectfirst', 'selectfirst_by', 'selectone', 'selectone_by', 'get_by', 'join_to', 'join_via', 'count', 'count_by', 'options', 'instances'): + _monkeypatch_query_method(name, ctx, class_) + for name in ('refresh', 'expire', 'delete', 'expunge', 'update'): _monkeypatch_session_method(name, ctx, class_) m = mapper(class_, extension=extension, *args, **kwargs) diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index b27e823703..479f13a8a1 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -214,9 +214,9 @@ def select(columns=None, whereclause=None, from_obj=[], **kwargs): rendered in the ``FROM`` clause of this select statement. """ - scalar = kwargs.pop('scalar', False) - if scalar: + if 'scalar' in kwargs: util.warn_deprecated('scalar option is deprecated; see docs for details') + scalar = kwargs.pop('scalar', False) s = Select(columns, whereclause=whereclause, from_obj=from_obj, **kwargs) if scalar: return s.as_scalar()