Skip to content

Instantly share code, notes, and snippets.

@TallGirlVanessa
Created January 31, 2014 23:32
Show Gist options
  • Save TallGirlVanessa/8745448 to your computer and use it in GitHub Desktop.
Save TallGirlVanessa/8745448 to your computer and use it in GitHub Desktop.
SQLAlchemy monkeypatch
class _PatchedEngineConnector(_EngineConnector):
def get_engine(self):
with self._lock:
uri = self.get_uri()
echo = self._app.config['SQLALCHEMY_ECHO']
encoding = self._app.config.get('SQLALCHEMY_ENCODING')
if (uri, echo) == self._connected_for:
return self._engine
info = make_url(uri)
options = {'convert_unicode': True}
self._sa.apply_pool_defaults(self._app, options)
self._sa.apply_driver_hacks(self._app, info, options)
if echo:
options['echo'] = True
if encoding:
options['encoding'] = encoding
self._engine = rv = sqlalchemy.create_engine(info, **options)
if _record_queries(self._app):
_EngineDebuggingSignalEvents(self._engine,
self._app.import_name).register()
self._connected_for = (uri, echo)
return rv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment