ソースを参照

Merge branch 'develop' of github.com:tracim/tracim_backend into feature/578_add_api_for_workspace/apps

Guénaël Muller 6 年 前
コミット
ad7525b38e
共有2 個のファイルを変更した28 個の追加8 個の削除を含む
  1. 16 0
      tracim/lib/utils/request.py
  2. 12 8
      tracim/lib/webdav/middlewares.py

+ 16 - 0
tracim/lib/utils/request.py ファイルの表示

42
         # User found from request headers, content, distinct from authenticated
42
         # User found from request headers, content, distinct from authenticated
43
         # user
43
         # user
44
         self._user_candidate = None  # type: User
44
         self._user_candidate = None  # type: User
45
+        # INFO - G.M - 18-05-2018 - Close db at the end of the request
46
+        self.add_finished_callback(self._cleanup)
45
 
47
 
46
     @property
48
     @property
47
     def current_workspace(self) -> Workspace:
49
     def current_workspace(self) -> Workspace:
98
             self.candidate_user = get_candidate_user(self)
100
             self.candidate_user = get_candidate_user(self)
99
         return self._user_candidate
101
         return self._user_candidate
100
 
102
 
103
+    def _cleanup(self, request: 'TracimRequest') -> None:
104
+        """
105
+        Close dbsession at the end of the request in order to avoid exception
106
+        about not properly closed session or "object created in another thread"
107
+        issue
108
+        see https://github.com/tracim/tracim_backend/issues/62
109
+        :param request: same as self, request
110
+        :return: nothing.
111
+        """
112
+        self._current_user = None
113
+        self._current_workspace = None
114
+        self.dbsession.close()
115
+
116
+
101
     @candidate_user.setter
117
     @candidate_user.setter
102
     def candidate_user(self, user: User) -> None:
118
     def candidate_user(self, user: User) -> None:
103
         if self._user_candidate is not None:
119
         if self._user_candidate is not None:

+ 12 - 8
tracim/lib/webdav/middlewares.py ファイルの表示

263
         self.app_config.configure_filedepot()
263
         self.app_config.configure_filedepot()
264
 
264
 
265
     def __call__(self, environ, start_response):
265
     def __call__(self, environ, start_response):
266
-        with transaction.manager as tm:
267
-            dbsession = get_tm_session(self.session_factory, transaction.manager)
268
-            environ['tracim_tm'] = tm
269
-            environ['tracim_dbsession'] = dbsession
270
-            environ['tracim_cfg'] = self.app_config
271
-
272
-            return self._application(environ, start_response)
266
+        # TODO - G.M - 18-05-2018 - This code should not create trouble
267
+        # with thread and database, this should be verify.
268
+        # see https://github.com/tracim/tracim_backend/issues/62
269
+        tm = transaction.manager
270
+        dbsession = get_tm_session(self.session_factory, tm)
271
+        environ['tracim_tm'] = tm
272
+        environ['tracim_dbsession'] = dbsession
273
+        environ['tracim_cfg'] = self.app_config
274
+        app = self._application(environ, start_response)
275
+        dbsession.close()
276
+        return app
273
 
277
 
274
 
278
 
275
 class TracimUserSession(BaseMiddleware):
279
 class TracimUserSession(BaseMiddleware):
285
             session=environ['tracim_dbsession'],
289
             session=environ['tracim_dbsession'],
286
             config=environ['tracim_cfg'],
290
             config=environ['tracim_cfg'],
287
         ).get_one_by_email(environ['http_authenticator.username'])
291
         ).get_one_by_email(environ['http_authenticator.username'])
288
-        return self._application(environ, start_response)
292
+        return self._application(environ, start_response)