pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

OIDC: object has no attribute 'is_active' if OAUTH2_AUTO_CREATE_USER is false

Open maurerle opened this issue 2 months ago • 0 comments

Describe the bug

When having OAUTH2_AUTO_CREATE_USER = false the login of a user gives an error message 'NoneType' object has no attribute 'is_active'.

To Reproduce

Steps to reproduce the behavior:

  1. Set OAUTH2_AUTO_CREATE_USER = false
  2. Login with user which has not be added to pgadmin
  3. See the error

Expected behavior

A clear and helpful error message telling me that the user could not be created. Mention of OAUTH2_AUTO_CREATE_USER in the server logs would be very helpful as well.

Error message

2025-10-22 09:07:02,011: ERROR	pgadmin:	'NoneType' object has no attribute 'is_active'
Traceback (most recent call last):
  File "/venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/pgadmin4/pgadmin/authenticate/oauth2.py", line 56, in oauth_authorize
    status, msg = auth_obj.login()
                  ^^^^^^^^^^^^^^^^
  File "/pgadmin4/pgadmin/authenticate/__init__.py", line 298, in login
    status, msg = self.source.login(self.form)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/pgadmin4/pgadmin/authenticate/oauth2.py", line 256, in login
    return login_user(user), None
           ^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/flask_security/utils.py", line 185, in login_user
    if not _login_user(user, remember):  # pragma: no cover
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/flask_login/utils.py", line 180, in login_user
    if not force and not user.is_active:
                         ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'is_active'
  • pgAdmin version: [e.g. 6.15]
  • Mode: [e.g Desktop or Server]
  • Browser (if running in server mode): [e.g. chrome, safari]
  • Package type: [e.g. RPM, DEB, Python, Container, etc.]

Additional context

Add any other context about the problem here.

maurerle avatar Oct 22 '25 09:10 maurerle