How to avoid error when app is renamed and sessions are stored in db and shared through domains?

41 views
Skip to first unread message

Lisandro

unread,
Apr 23, 2015, 10:36:42 AM4/23/15
to web...@googlegroups.com
I have two apps running on production: "init" app, and "panel" app.
Both of them are using the same database (symlinked models and databases folder).
The sessions are stored in the db.
The main app is "init", so I'm connecting to session like this:

session.connect(request, response, db=db, masterapp='init')

In the database, I can see that the session table is called "web2py_session_init".


Now I need to rename both apps and serve both of them on domaind and subdomain, so I did this:
 - renamed "init" to "website"; the app is now served on website.com domain.
 - renamed "panel" to "website_panel"; the app is now served on panel.website.com domain

The main app now is "website_panel".

In order to mantain sessions through main domain and subdomain, I added this sentence after the session.connect, so I ended up with this:
session.connect(request, response, db=db, masterapp='init')
response.cookies[response.session_id_name]['domain'] = 'website.com'

But I'm receiving this error:
Traceback (most recent call last):
 
File "/home/gonguinguen/medios/gluon/restricted.py", line 227, in restricted
   
exec ccode in environment
 
File "/home/gonguinguen/medios/applications/website/models/db.py", line 10, in <module>
   
response.cookies[response.session_id_name]['domain'] = 'website.com'
KeyError: 'session_id_init'


First thing I tryied was to change masterapp parameter value, like this:
session.connect(request, response, db=db, masterapp='website_panel')
response.cookies[response.session_id_name]['domain'] = 'website.com'

but in this case, an error is raised saying that the table "web2py_session_website_panel" doesn't exists.
I'm not shure why web2py doesn't create the table. I have migrations enabled,


I also tryied manually renaming the table and the corresponding file under databases folder, but in this case I receive the following error:
Traceback (most recent call last):
 
File "/home/gonguinguen/medios/gluon/restricted.py", line 227, in restricted
   
exec ccode in environment
 
File "/home/gonguinguen/medios/applications/website/models/db.py", line 8, in <module>
   
response.cookies[response.session_id_name]['domain'] = 'website.com'
KeyError: 'session_id_website_panel'


Also tryied deleting the old session table and the corresponding file under databases folder, but in this case again I receive an error saying that the table "web2py_session_website_panel" doesn't exists. So I'm stucked here. Any tip? Thanks in advance.

Lisandro

unread,
Apr 23, 2015, 2:57:57 PM4/23/15
to web...@googlegroups.com
I could get it to work, however I'm still concerned about something.
This is what I have and it is working:

session.connect(request, response, db=db, masterapp='init')
response.cookies[response.session_id_name]['domain'] = 'website.com'

As I said before, the two apps were renamed, keeping the database. 
So, regardless the new applications names, the session table is still named "web2py_session_init", and that's why I think it is working with masterapp='init'.

However, should I be worried about setting masterapp with an app that doesn't exist? The book says "If you want two or more applications to share sessions, set masterapp to the name of the master application.", but I coundn't find specifications about if that app should exist or not.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages