- def execute(self, clause, params=None, *args, **kwargs):
- if not params:
- params = {}
- params.setdefault('_default_language_id', self.default_language_id)
-
- return super(MultilangSession, self).execute(
- clause, params, *args, **kwargs)
+ def connection(self, *args, **kwargs):
+ """Monkeypatch the connection. Not pretty at all.
+ """
+ conn = super(MultilangSession, self).connection(*args, **kwargs)
+ original_execute = conn.execute
+ if original_execute.__name__ != 'monkeypatched_execute':
+ def monkeypatched_execute(statement, *multiparams, **params):
+ if isinstance(statement, Select):
+ boundparams = dict(multiparams[0])
+ boundparams.setdefault('_default_language_id', self.default_language_id)
+ multiparams = [boundparams] + list(multiparams[1:])
+ return original_execute(statement, *multiparams, **params)
+ conn.execute = monkeypatched_execute
+ return conn