[session] Stop relying on _sessions to synchronize living session
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 10 Mar 2017 16:41:10 +0100
changeset 12025 ba79f4a4f5d8
parent 12024 5f46195b9595
child 12026 c21b399c9269
[session] Stop relying on _sessions to synchronize living session by doing what we currently do in pyramid. Also, attempt to synchronize CWUser's class sounds like a dark corner case handling that should be removed in favor of short lived user objects (beside it shouldn't occur except during migration).
cubicweb/hooks/syncschema.py
cubicweb/hooks/syncsession.py
cubicweb/pyramid/__init__.py
cubicweb/pyramid/syncsession.py
cubicweb/server/repository.py
--- a/cubicweb/hooks/syncschema.py	Fri Mar 10 12:01:31 2017 +0100
+++ b/cubicweb/hooks/syncschema.py	Fri Mar 10 16:41:10 2017 +0100
@@ -217,10 +217,6 @@
             repo.schema.rebuild_infered_relations()
             # trigger vreg reload
             repo.set_schema(repo.schema)
-            # CWUser class might have changed, update current session users
-            cwuser_cls = self.cnx.vreg['etypes'].etype_class('CWUser')
-            for session in repo._sessions.values():
-                session.user.__class__ = cwuser_cls
         except Exception:
             self.critical('error while setting schema', exc_info=True)
 
--- a/cubicweb/hooks/syncsession.py	Fri Mar 10 12:01:31 2017 +0100
+++ b/cubicweb/hooks/syncsession.py	Fri Mar 10 16:41:10 2017 +0100
@@ -24,11 +24,9 @@
 from cubicweb.entities.authobjs import user_session_cache_key
 
 
-# take cnx and not repo because it's needed for other sessions implementation (e.g. pyramid)
-def get_user_sessions(cnx, ueid):
-    for session in cnx.repo._sessions.values():
-        if ueid == session.user.eid:
-            yield session
+def get_user_sessions(cnx, user_eid):
+    if cnx.user.eid == user_eid:
+        yield cnx
 
 
 class CachedValueMixin(object):
--- a/cubicweb/pyramid/__init__.py	Fri Mar 10 12:01:31 2017 +0100
+++ b/cubicweb/pyramid/__init__.py	Fri Mar 10 16:41:10 2017 +0100
@@ -231,7 +231,6 @@
         config.include(name)
 
     config.include('cubicweb.pyramid.core')
-    config.include('cubicweb.pyramid.syncsession')
 
     if asbool(config.registry.settings.get('cubicweb.bwcompat', True)):
         config.include('cubicweb.pyramid.bwcompat')
--- a/cubicweb/pyramid/syncsession.py	Fri Mar 10 12:01:31 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""Override cubicweb's syncsession hooks to handle them in the pyramid's way"""
-
-from logilab.common.decorators import monkeypatch
-from cubicweb.hooks import syncsession
-
-
-def includeme(config):
-
-    @monkeypatch(syncsession)
-    def get_user_sessions(cnx, user_eid):
-        if cnx.user.eid == user_eid:
-            yield cnx
--- a/cubicweb/server/repository.py	Fri Mar 10 12:01:31 2017 +0100
+++ b/cubicweb/server/repository.py	Fri Mar 10 16:41:10 2017 +0100
@@ -45,7 +45,7 @@
 from cubicweb import (CW_MIGRATION_MAP, QueryError,
                       UnknownEid, AuthenticationError, ExecutionError,
                       BadConnectionId,
-                      UniqueTogetherError, onevent, ViolatedConstraint)
+                      UniqueTogetherError, ViolatedConstraint)
 from cubicweb import set_log_methods
 from cubicweb import cwvreg, schema, server
 from cubicweb.server import utils, hook, querier, sources
@@ -242,17 +242,6 @@
         # the hooks manager
         self.hm = hook.HooksManager(self.vreg)
 
-        # registry hook to fix user class on registry reload
-        @onevent('after-registry-reload', self)
-        def fix_user_classes(self):
-            # After registry reload the 'CWUser' class used for CWEtype
-            # changed.  So any existing user object have a different class than
-            # the new loaded one. We are hot fixing this.
-            usercls = self.vreg['etypes'].etype_class('CWUser')
-            for session in self._sessions.values():
-                if not isinstance(session.user, InternalManager):
-                    session.user.__class__ = usercls
-
     def bootstrap(self):
         self.info('starting repository from %s', self.config.apphome)
         self.shutting_down = False