FS#70918 - [pgadmin4] Do not work since flask-2.0 update

Attached to Project: Community Packages
Opened by Bastien Durel (bastiendurel) - Monday, 17 May 2021, 14:44 GMT
Last edited by Jelle van der Waa (jelly) - Sunday, 03 September 2023, 15:32 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Levente Polyak (anthraxx)
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 27
Private No

Details

Hello.

python-flask had been upgraded to 2.0 on may 12. Since this date, pgadmin4 wsgi server cannot start anymore, as flask API changed.

Traceback (most recent call last):
File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 94, in <module>
app = create_app()
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 630, in create_app
app.register_blueprint(module)
File "/usr/lib/python3.9/site-packages/flask/scaffold.py", line 54, in wrapper_func
return f(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/flask/app.py", line 1022, in register_blueprint
blueprint.register(self, options)
File "/usr/lib/pgadmin4/web/pgadmin/utils/__init__.py", line 66, in register
super(PgAdminModule, self).register(app, options, first_registration)
TypeError: register() takes 3 positional arguments but 4 were given

I've tried to remove the 'first_registration' parameter, but got another error :

Traceback (most recent call last):
File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 94, in <module>
app = create_app()
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 628, in create_app
for module in app.find_submodules('pgadmin'):
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 79, in find_submodules
module = import_module(module_name)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/lib/pgadmin4/web/pgadmin/preferences/__init__.py", line 26, in <module>
from pgadmin.browser.server_groups import ServerGroupModule as sgm
File "/usr/lib/pgadmin4/web/pgadmin/browser/server_groups/__init__.py", line 20, in <module>
from pgadmin.browser.utils import NodeView
File "/usr/lib/pgadmin4/web/pgadmin/browser/utils.py", line 16, in <module>
from flask.views import View, MethodViewType, with_metaclass
ImportError: cannot import name 'with_metaclass' from 'flask.views' (/usr/lib/python3.9/site-packages/flask/views.py)

As flask version was bumped from 1.1 to 2.0, I expect there may be a lot of API changes, as as I don't know flask (and not many python), I won't be able to dig more
This task depends upon

Closed by  Jelle van der Waa (jelly)
Sunday, 03 September 2023, 15:32 GMT
Reason for closing:  Deferred
Additional comments about closing:  Package dropped to AUR
Comment by Christoph (cpaulik) - Wednesday, 16 June 2021, 12:07 GMT
The workaround that I found is the following

Download older package versions of python-flask and python-flask-security and then install locally

sudo pacman -U python-flask-security-too-3.3.3-3-any.pkg.tar.zst
sudo pacman -U python-flask-1.1.2-4-any.pkg.tar.zst

Comment by loqs (loqs) - Wednesday, 16 June 2021, 14:26 GMT
Does rebuilding pgadmin4 with the attached diff applied resolve the issue?
Comment by Bastien Durel (bastiendurel) - Wednesday, 16 June 2021, 14:56 GMT
No, it does not.
I had to refresh the sha512sum's to build the package, but it seems incomplete

```
bastien@data-bastien:~$ pgadmin4
/usr/bin/pgadmin4: ligne 3: /usr/lib/pgadmin4/runtime/pgAdmin4: Aucun fichier ou dossier de ce type
bastien@data-bastien:~$ ls /usr/lib/pgadmin4/
docs web
bastien@data-bastien:~$
```
Comment by Milutin Jovanović (mikijov) - Wednesday, 16 June 2021, 16:39 GMT
I have resorted to running pgAdmin in docker until this is resolved.
https://hub.docker.com/r/dpage/pgadmin4/
Comment by aaron (refriedjello) - Wednesday, 16 June 2021, 19:25 GMT
I am running into this same error on a fresh install of pgadmin4 on CentOS 7. Does anyone know how I could implement a work-around for my system? I cannot see any older versions of python-flask available from the repos.

flask --version
Python 3.6.8
Flask 2.0.1
Werkzeug 2.0.1

The command 'yum list python-flask --showduplicates' does not show any other available versions.
Comment by Arti Zirk (arti) - Wednesday, 16 June 2021, 19:30 GMT
Im currently just creating a virtualenv and using pgadmin from there

python3 -m venv venv
source venv/bin/activate
pip install pgadmin4
venv/bin/pgadmin4
Comment by aaron (refriedjello) - Wednesday, 16 June 2021, 19:35 GMT
Arti - what version of flask do you have installed, and what OS version are you using? Thanks,
Comment by Arti Zirk (arti) - Wednesday, 16 June 2021, 20:07 GMT
If you use Python 3-s venv to install pgadmin then it will use flask 1.1.4.

I use Arch Linux but the same instructions also should work on CentOS and Debian.

I known that official pgadmin4 Debian packages also use virtualenv so that older Flask can be used without interfering with OS packaged Flask version.
Comment by aaron (refriedjello) - Wednesday, 16 June 2021, 20:40 GMT
I was able to work around this by uninstalling python-flask using yum, downloading an older pip file for Flask and installing it via pip. I pulled this Flask file:

https://files.pythonhosted.org/packages/4d/5b/2d145f5fe718b2f15ebe69240538f06faa8bbb76488bf962091db1f7a26d/Flask-1.1.4.tar.gz
Comment by loqs (loqs) - Sunday, 20 June 2021, 22:21 GMT
Upstream was supposed to have fixed flask compatibility but using the latest git commit 4e067835c, see attached src bundle still producing issues.
Comment by Bastien Durel (bastiendurel) - Monday, 21 June 2021, 08:27 GMT
It seems to lack some dependencies :

File "/usr/lib/pgadmin4/web/pgadmin/about/__init__.py", line 20, in <module>
import httpagentparser
ModuleNotFoundError: No module named 'httpagentparser'

After installing python-httpagentparser, it lacks another module I did not find via a quick search :

File "/usr/lib/pgadmin4/web/pgadmin/about/__init__.py", line 22, in <module>
from user_agents import parse
ModuleNotFoundError: No module named 'user_agents'
Comment by loqs (loqs) - Monday, 21 June 2021, 11:54 GMT
@bastiendurel that is further than I got. The additional dependencies are
https://aur.archlinux.org/packages/python-user-agents/ which requires https://aur.archlinux.org/packages/python-ua-parser/ and https://aur.archlinux.org/packages/python-httpagentparser/

Added the dependencies to both the git and 5.4 versions. Do these versions work for you?


Comment by Bastien Durel (bastiendurel) - Monday, 21 June 2021, 13:39 GMT

No, they don't :

pgadmin4-5.4-1:

Traceback (most recent call last):
File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 98, in <module>
app = create_app()
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 691, in create_app
app.register_blueprint(module)
File "/usr/lib/python3.9/site-packages/flask/scaffold.py", line 56, in wrapper_func
return f(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/flask/app.py", line 1030, in register_blueprint
blueprint.register(self, options)
File "/usr/lib/pgadmin4/web/pgadmin/utils/__init__.py", line 69, in register
super(PgAdminModule, self).register(app, options, first_registration)
TypeError: register() takes 3 positional arguments but 4 were given


pgadmin4-5.4.r2.g4e067835c-1:
Traceback (most recent call last):
File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 98, in <module>
app = create_app()
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 691, in create_app
app.register_blueprint(module)
File "/usr/lib/python3.9/site-packages/flask/scaffold.py", line 56, in wrapper_func
return f(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/flask/app.py", line 1030, in register_blueprint
blueprint.register(self, options)
File "/usr/lib/pgadmin4/web/pgadmin/utils/__init__.py", line 69, in register
super(PgAdminModule, self).register(app, options, first_registration)
TypeError: register() takes 3 positional arguments but 4 were given


Looks like we're back to the first error
Comment by loqs (loqs) - Monday, 21 June 2021, 14:26 GMT
This is the error I am stuck at, pgadmin4-5.4-1
pgadmin4
NOTE: Configuring authentication for DESKTOP mode.
2021-06-21 14:22:33,639: ERROR pgadmin: Exception in database migration.
NOTE: Configuring authentication for DESKTOP mode.
2021-06-21 14:22:34,270: ERROR pgadmin: Database migration failed
2021-06-21 14:22:34,272: ERROR pgadmin: Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: table version already exists

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 379, in upgrade_db
db_upgrade(app)
File "/usr/lib/pgadmin4/web/pgadmin/setup/db_upgrade.py", line 25, in db_upgrade
flask_migrate.upgrade(migration_folder)
File "/usr/lib/python3.9/site-packages/flask_migrate/__init__.py", line 92, in wrapped
f(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/flask_migrate/__init__.py", line 162, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/usr/lib/python3.9/site-packages/alembic/command.py", line 294, in upgrade
script.run_env()
File "/usr/lib/python3.9/site-packages/alembic/script/base.py", line 490, in run_env
util.load_python_file(self.dir, "env.py")
File "/usr/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
module = load_module_py(module_id, path)
File "/usr/lib/python3.9/site-packages/alembic/util/compat.py", line 182, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/lib/pgadmin4/web/pgadmin/setup/../../migrations/env.py", line 93, in <module>
run_migrations_online()
File "/usr/lib/pgadmin4/web/pgadmin/setup/../../migrations/env.py", line 86, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/usr/lib/python3.9/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
self.get_context().run_migrations(**kw)
File "/usr/lib/python3.9/site-packages/alembic/runtime/migration.py", line 561, in run_migrations
step.migration_fn(**kw)
File "/usr/lib/pgadmin4/web/migrations/versions/fdc58d9bd449_.py", line 45, in upgrade
op.create_table('version',
File "<string>", line 8, in create_table
File "<string>", line 3, in create_table
File "/usr/lib/python3.9/site-packages/alembic/operations/ops.py", line 1072, in create_table
return operations.invoke(op)
File "/usr/lib/python3.9/site-packages/alembic/operations/base.py", line 354, in invoke
return fn(self, operation)
File "/usr/lib/python3.9/site-packages/alembic/operations/toimpl.py", line 101, in create_table
operations.impl.create_table(table)
File "/usr/lib/python3.9/site-packages/alembic/ddl/impl.py", line 277, in create_table
self._exec(schema.CreateTable(table))
File "/usr/lib/python3.9/site-packages/alembic/ddl/impl.py", line 146, in _exec
return conn.execute(construct, multiparams)
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
return meth(self, multiparams, params)
File "/usr/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1068, in _execute_ddl
ret = self._execute_context(
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
self._handle_dbapi_exception(
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
util.raise_(
File "/usr/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
raise exception
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
self.dialect.do_execute(
File "/usr/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 608, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table version already exists
[SQL:
CREATE TABLE version (
name VARCHAR(32) NOT NULL,
value INTEGER NOT NULL,
PRIMARY KEY (name)
)

]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
....
cut repeating fault output off here
Comment by Bastien Durel (bastiendurel) - Tuesday, 22 June 2021, 07:49 GMT
maybe you should drop the table ? There may had been an incomplete update once ?
Comment by loqs (loqs) - Tuesday, 22 June 2021, 20:05 GMT
I should have stated, that output was created after I removed ~/.pgadmin although it mentions database migration in the output.
It appears it creates the table, then there is some error before it can populate it, it then tries to create the table again.
Comment by Eli Schwartz (eschwartz) - Tuesday, 22 June 2021, 20:40 GMT
Upstream's bugtracker requires an account even to search the list of open tickets.

...

Does anyone have any idea if upstream is tracking this topic?
Comment by loqs (loqs) - Tuesday, 22 June 2021, 21:38 GMT
@eschwartz sorry not registered either. Does the 5.4 src.tar.gz as I have updated it seem reasonable to you? Does it work for you?
5.4 dropped all C code along with other layout changes which meant a lot of changes to the PKGBUILD.
As users installing with PIP were not having issues, I was inclined to believe it was still a packaging issue.
Comment by Bastien Durel (bastiendurel) - Wednesday, 23 June 2021, 09:21 GMT
Using pip in a venv let you use the 1.x-version of flask, that's why it works :/

Upstream seems to have handled the flask-security-too-4 issue, but not the flask-2 one.
Comment by Miles Sabin (milessabin) - Monday, 05 July 2021, 17:06 GMT
I'm now also seeing an issue with the recent upgrade of python-psycopg2 to 2.9.1-1 ... after that I see,

```
'psycopg2.extensions.Column' object has no attribute '_asdict'
```

when attempting to connect to a database.

Downgrading to 2.8.6-4 fixes the problem.
Comment by Levente Polyak (anthraxx) - Monday, 05 July 2021, 19:31 GMT
it doesnt look like i have the time right now to create compatibility patches unfortunately, sorry. If anyone proposes a working fix i would apply it asap
Comment by Eli Schwartz (eschwartz) - Monday, 05 July 2021, 19:46 GMT
Maybe we should add legacy python-psycopg2.8 python-flask1.1 etc. packages and make pgadmin4 depend on those for the time being?

It really is a shame the upstream bugtracker cannot be anonymously viewed...
Comment by Levente Polyak (anthraxx) - Monday, 05 July 2021, 19:57 GMT
@eli: that would create too much conflicts because you can only have a single version, which i wont do here so unfortunatly a venv would make more sense. or get it patched, but i really can't bring up the required time right now
Comment by Thenujan (Thenujan) - Thursday, 26 August 2021, 06:10 GMT
i copied the following solution from stackoverflow this works perfectly fine for me
https://stackoverflow.com/questions/67610220/pgadmin4-error-modulenotfounderror-no-module-named-email-validator

You can run pgadmin4 via docker, and link it directly to the host network.

docker run -e 'PGADMIN_LISTEN_PORT=8080' \
-e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' \
-e "PGADMIN_DEFAULT_PASSWORD=secret" \
--network="host" \
dpage/pgadmin4:latest
Then visit http://localhost:8080, login with user@domain.com:secret. You can now add servers like you might normally, just specify "localhost" as the host and your normal username (I think that's how arch configures access by default).
Comment by Álvaro Herrera (alvherre) - Wednesday, 27 July 2022, 09:59 GMT
Hello. pgAdmin4 has been upgraded to Flask4 in November 2021: https://git.postgresql.org/gitweb/?p=pgadmin4.git;a=commit;h=d644b4f94ec71af78a46434121bce0fcd626a2dc
I think that was released with pgAdmin4 6.3.

Maybe updating the Arch packages to the latest (6.11 or perhaps 6.12) is a good fix for this problem.
Comment by nvb (nvb) - Tuesday, 16 May 2023, 07:13 GMT
Hello,

the issue itself "pgadmin4 is not starting" still exists (16.05.2023).
On a fresh installed arch linux with a fresh installed pgadmin4, all I see is a Window with "Starting pgAdmin4 server..."
From the command line, I see the following lines of code

```bash
QCoreApplication::applicationFilePath: Please instantiate the QApplication object first
QCoreApplication::applicationFilePath: Please instantiate the QApplication object first
Semaphore name: "pgadmin4-<string: username>-<string: lots_of_characters>-sema"
Shared memory segment name: "pgadmin4-sl90fyqo-a59283b86ae8ae85d20fdf770d799dd7-shmem"
Python path: "/usr/lib/python3.11:/usr/lib/python3.11/lib-dynload:/usr/lib/python3.11/site-packages"
Python Home: "/usr/lib/python3.11"
Webapp path: "/usr/lib/pgadmin4/web/pgAdmin4.py"
```

After reading the comment section, this seams to be a longer issue. As a user, it is not satisfying to install a software that is not working.

So my best idea is to:

* Either update the package again and keep fingers crossed all is working
* Update the wiki section to either use a docker container or pip (maybe I will do that this week to guide other peoples to alternatives :-))
* Remove this package from the shoulders of the maintainer (he really has enough other areas to take care of)

Please, don't think my comment has any intention of spreading anger or frustration.

Best regards and thanks for the maintenance effort so far.

Comment by Buggy McBugFace (bugbot) - Tuesday, 08 August 2023, 19:11 GMT
This is an automated comment as this bug is open for more then 2 years. Please reply if you still experience this bug otherwise this issue will be closed after 1 month.

Loading...