Search code examples
pyramid

how to override Pyramid's session factory?


I'm trying to use both pyramid_persona and pyramid_beaker in the same project. However both are setting a session_factory in their includeme() method, and this leads to this error:

pyramid.exceptions.ConfigurationConflictError: Conflicting configuration actions
  For: <InterfaceClass pyramid.interfaces.ISessionFactory>
Line 173 of file /home/pyramid/project_env/local/lib/python2.7/site-packages/pyramid_beaker/__init__.py:
  config.set_session_factory(session_factory)
Line 50 of file /home/pyramid/project_env/local/lib/python2.7/site-packages/pyramid_persona/__init__.py:
  config.set_session_factory(session_factory)

I'm importing these modules in the main() method from  __init__.py like this:

config.include("pyramid_persona")
config.include("pyramid_beaker")

with pyramid v. 1.5.1, pyramid_beaker 0.8 and pyramid_persona 1.5.

Is there a way to tell Pyramid that it's ok to override the session_factory?


Solution

  • You can override the session factory after including the addons by invoking config.set_session_factory yourself. Alternatively select the one you want and call config.commit between them. This is part of Pyramid's conflict resolution mechanism.