Re: [PATCH] Work with newer Flask-Security. - Mailing list pgadmin-hackers

From Ashesh Vashi
Subject Re: [PATCH] Work with newer Flask-Security.
Date
Msg-id CAG7mmowJwcDWgXvCKhg4VSoK6Qq57nynbcpuLKO_aheUhoT6JA@mail.gmail.com
Whole thread Raw
In response to [PATCH] Work with newer Flask-Security.  (Wouter van Kesteren <woutershep@gmail.com>)
Responses Re: [PATCH] Work with newer Flask-Security.
List pgadmin-hackers
Harshal,

Please take a look at it.

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company


http://www.linkedin.com/in/asheshvashi


On Mon, Aug 7, 2017 at 6:46 PM, Wouter van Kesteren <woutershep@gmail.com> wrote:
I installed it on my system and i got the following error:

Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1610, in full_dispatch_request
    rv = self.preprocess_request()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask/app.py", line 1831, in preprocess_request
    rv = func()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_principal.py", line 477, in _on_before_request
    identity = loader()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_security/core.py", line 245, in _identity_loader
    if not isinstance(current_user._get_current_object(), AnonymousUserMixin):
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/werkzeug/local.py", line 306, in _get_current_object
    return self.__local()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_login/utils.py", line 26, in <lambda>
    current_user = LocalProxy(lambda: _get_user())
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_login/utils.py", line 302, in _get_user
    current_app.login_manager._load_user()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_login/login_manager.py", line 316, in _load_user
    return self.reload_user()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_login/login_manager.py", line 278, in reload_user
    user = self.user_callback(user_id)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.4/site-packages/flask_security/core.py", line 221, in _user_loader
    return _security.datastore.find_user(id=user_id)
AttributeError: 'NoneType' object has no attribute 'find_user'

My system has Flask-Security 3.0.0 which contains a patch to Security.init_app

-        if not self.datastore:
-            self.datastore = datastore
-        datastore = self.datastore
+        self.app = app
+        self.datastore = datastore

https://github.com/mattupstate/flask-security/commit/3701b91d4d3e41036872a3f35db51e44e0681109

To get the old behavior we need to pass the datastore along again else
it gets overruled by the default None.
---
 web/pgadmin/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index cd18b1f8..f4f7e385 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -308,7 +308,7 @@ def create_app(app_name=None):
     app.config.update(dict(SECRET_KEY=config.SECRET_KEY))
     app.config.update(dict(SECURITY_PASSWORD_SALT=config.SECURITY_PASSWORD_SALT))

-    security.init_app(app)
+    security.init_app(app, user_datastore)

     app.session_interface = create_session_interface(app)

--
2.13.3



pgadmin-hackers by date:

Previous
From: Dave Page
Date:
Subject: Re: Unified server/desktop config
Next
From: Chethana Kumar
Date:
Subject: Re: [pgAdmin4][Patch]: Allow user to cancel long running queries from dashboard