好的,我最终
search_path使用Pyramid的
NewRequest事件在每个请求的开头进行了修改:
from pyramid import eventsdef on_new_request(event): schema_name = _figire_out_schema_name_from_request(event.request) DBSession.execute("SET search_path TO %s" % schema_name)def app(global_config, **settings): """ This function returns a WSGI application. It is usually called by the PasteDeploy framework during ``paster serve``. """ .... config.add_subscriber(on_new_request, events.NewRequest) return config.make_wsgi_app()只要您将事务管理留给Pyramid(即不要手动提交/回退事务,让Pyramid在请求结束时执行此操作),就可以很好地工作-
可以,因为手动提交事务无论如何都不是一个好方法。



