Re: [PATCH] Work with newer Flask-Security.

From: Dave Page <dpage(at)pgadmin(dot)org>
To: Harshal Dhumal <harshal(dot)dhumal(at)enterprisedb(dot)com>
Cc: Ashesh Vashi <ashesh(dot)vashi(at)enterprisedb(dot)com>, pgadmin-hackers(at)lists(dot)postgresql(dot)org, Wouter van Kesteren <woutershep(at)gmail(dot)com>
Subject: Re: [PATCH] Work with newer Flask-Security.
Date: 2017-09-18 10:46:35
Message-ID: CA+OCxoxa-OEuiC=jm5eA=rcFds3hZyZ00jndHtuZ+4Qrmo+P_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers

Thanks, applied.

On Wed, Aug 9, 2017 at 3:19 PM, Harshal Dhumal <
harshal(dot)dhumal(at)enterprisedb(dot)com> wrote:

> Hi,
>
> I tested this change with Flask-Security 3.0.0 and 1.7.5 (we ship pgAdmin4
> with 1.7.5) and with 2.7 and 3.0+.
> This is working as expected.
>
> Apart from this I also found some other issues with User management.
> I have created RM2641 <https://redmine.postgresql.org/issues/2641> for
> these issue and also attached patch from same.
>
>
> Thanks
>
>
> --
> *Harshal Dhumal*
> *Sr. Software Engineer*
>
> EnterpriseDB India: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
> On Mon, Aug 7, 2017 at 7:08 PM, Ashesh Vashi <
> ashesh(dot)vashi(at)enterprisedb(dot)com> wrote:
>
>> Harshal,
>>
>> Please take a look at it.
>>
>> --
>>
>> Thanks & Regards,
>>
>> Ashesh Vashi
>> EnterpriseDB INDIA: Enterprise PostgreSQL Company
>> <http://www.enterprisedb.com>
>>
>>
>> *http://www.linkedin.com/in/asheshvashi*
>> <http://www.linkedin.com/in/asheshvashi>
>>
>> On Mon, Aug 7, 2017 at 6:46 PM, Wouter van Kesteren <woutershep(at)gmail(dot)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/3701b91
>>> d4d3e41036872a3f35db51e44e0681109
>>>
>>> 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.SECURI
>>> TY_PASSWORD_SALT))
>>>
>>> - security.init_app(app)
>>> + security.init_app(app, user_datastore)
>>>
>>> app.session_interface = create_session_interface(app)
>>>
>>> --
>>> 2.13.3
>>>
>>>
>>>
>>
>

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgadmin-hackers by date

  From Date Subject
Next Message Dave Page 2017-09-18 10:55:08 pgAdmin 4 commit: Fix error message regexp in the query tool that could
Previous Message Dave Page 2017-09-18 10:46:01 pgAdmin 4 commit: Fix user manager role handling. Fixes #2641