We are running odoo on two dedicated servers with the same database. A load balancer distribute the requests to both servers. The problem is that both servers don't know the user sessions of each other server because the sessions are saved on the filesystem (werkzeug.contrib.sessions.FilesystemSessionStore, see openerp/http.py -> Root -> session_store). So I thought I overwrite this session with an own postgres session store by a new module (which I want to contribute if it's done).
Ok, this is the theory and it works - at least if the module is already installed and the database is known at the start of odoo (e.g. with -d <database>). The problem is that the module file is only loaded if the module is installed (what is good). But if this file is loaded to late then other functions have already fetched the session store. So my overwritings are too late.
Here is an minimized example of my module:
from openerp.http import OpenERPSession, Root
from openerp.tools.func import lazy_property
from werkzeug.contrib.sessions import SessionStore
class PostgresSessionStore(SessionStore):
# some functions which are already implemented
@lazy_property
def session_store(self):
return PostgresSessionStore(session_class=OpenERPSession)
Root.session_store = session_store
Now is my question: Do you know a better way to replace the session store without overwriting the odoo core so that the session store is replaced if the module is installed later or database is given later? I thought about some hacks like in [1] but I think this is not the good way.
[1] https://benkurtovic.com/2015/01/28/python-object-replacement.html
I'm also very interested in this. I created a simple module that stores the sessions in Redis, but got stuck in the same place as you. I think the proper way would be to create a parameter to Odoo configuration file (eg. session_store = werkzeug.contrib.sessions.FilesystemSessionStore), modify http.py to read the session storage class from the configuration file and file a pull request to Odoo 8.0. I just don't know if Odoo S.A. will accept such pull requests, but maybe we should at least try.
@Miku: This idea sounds good. How is your process? Did you achieved something like this? Or should I try my luck on this?
I created a PR for this: https://github.com/odoo/odoo/pull/7937
Hi @Miku Laitinen
I did the same in OpenERP v7. There was no other way to do it when you config workers