Odoo Help


Replace Session Store of odoo/werkzeug

on 6/16/15, 10:46 AM 5,074 views

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

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 Laitinen
on 7/23/15, 7:29 AM

@Miku: This idea sounds good. How is your process? Did you achieved something like this? Or should I try my luck on this?

on 8/5/15, 11:39 AM

I created a PR for this: https://github.com/odoo/odoo/pull/7937

on 8/6/15, 10:45 AM

Hi @Miku Laitinen
I did the same in OpenERP v7. There was no other way to do it when you config workers

Axel Mendoza
on 10/1/15, 1:41 AM

Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/1/15, 2:09 AM

In Odoo this can be implemented as a command and used to run Odoo with the needed calls to the bootstrap code and changes to http.py before been loaded because for commands the modules are loaded ok. The default command is server who bootstrap the Odoo server using the config options. Your command need to do pretty much the same but with changes in the right places

On 5/15/16, 10:18 PM

i have integrate redis to store odoo session.    thanks for https://gist.github.com/carlopires/1451947

you can try it use this branch  https://github.com/jeffery9/odoo/tree/odoo8-session-in-redis

On 12/8/15, 5:08 PM

I have two suggestions

1 - Why not use nfs to share session_dir?

2 - Implement a custom start script instead of odoo.py and reassign openerp.http.root to your override.

class NewRoot(openerp.http.Root)
    def session_store(self):
        return <your session store instance>

Then in your main method

def main()
import openerp
openerp.http.root = NewRoot() #override here

Hi, We had some trouble using NFS. It seems that there are locks on the files, resulting to page loading very slowly.

Isabelle Richard
on 1/28/16, 4:34 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

6 follower(s)


Asked: 6/16/15, 10:46 AM
Seen: 5074 times
Last updated: 5/15/16, 10:18 PM