Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove greenlet and add asyncio extra to sqlalchemy #895

Merged

Conversation

ychiucco
Copy link
Collaborator

@ychiucco ychiucco commented Oct 6, 2023

closes #894

Checklist before merging

  • I added an appropriate entry to CHANGELOG.md

@ychiucco ychiucco linked an issue Oct 6, 2023 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Oct 6, 2023

Coverage report

The coverage rate went from 92.83% to 92.83% ➡️
The branch rate is 83%.

None of the new lines are part of the tested code. Therefore, there is no coverage data about them.

@tcompa
Copy link
Collaborator

tcompa commented Oct 16, 2023

This PR should solve the original Apple-M1 issue reported in #747 (comment), while sticking to the solution recommended by sqlalchemy.

@jluethi would you mind re-trying the installation that triggered your original error? I don't have other Apple M1s available..

You would need to:

  1. Download this wheel file: fractal_server-1.3.12-py3-none-any.txt;
  2. Rename it to fractal_server-1.3.12-py3-none-any.whl;
  3. Run pip install fractal_server-1.3.12-py3-none-any.whl;
  4. Run fractalctl set-db and fractalctl start from a folder where you have the usual environment file.

If it all goes through, we can safely merge.

Thanks!

@jluethi
Copy link
Collaborator

jluethi commented Oct 16, 2023

@tcompa I can confirm that this installs without error on an M1 mac and then starts the server.

I have not tested server functionality with it then, but I guess that shouldn't be necessary, right?

@tcompa
Copy link
Collaborator

tcompa commented Oct 17, 2023

@tcompa I can confirm that this installs without error on an M1 mac and then starts the server.

Thanks!

I have not tested server functionality with it then, but I guess that shouldn't be necessary, right?

It isn't necessary, indeed.

If I remove greenlet from a working environment, even fractalctl set-db fails:

Run alembic.config, with argv=['-c', '/tmp/venv/lib/python3.10/site-packages/fractal_server/alembic.ini', 'upgrade', 'head']
fractal_server.app.db
Traceback (most recent call last):
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/app/db/__init__.py", line 32, in engine_async
    return cls._engine_async
AttributeError: type object 'DB' has no attribute '_engine_async'. Did you mean: 'engine_async'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/venv/bin/fractalctl", line 8, in <module>
    sys.exit(run())
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/__main__.py", line 83, in run
    set_db()
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/__main__.py", line 74, in set_db
    alembic.config.main(argv=alembic_args)
  File "/tmp/venv/lib/python3.10/site-packages/alembic/config.py", line 630, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/tmp/venv/lib/python3.10/site-packages/alembic/config.py", line 624, in main
    self.run_cmd(cfg, options)
  File "/tmp/venv/lib/python3.10/site-packages/alembic/config.py", line 601, in run_cmd
    fn(
  File "/tmp/venv/lib/python3.10/site-packages/alembic/command.py", line 399, in upgrade
    script.run_env()
  File "/tmp/venv/lib/python3.10/site-packages/alembic/script/base.py", line 578, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/tmp/venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/tmp/venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 109, in load_module_py
    spec.loader.exec_module(module)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/migrations/env.py", line 98, in <module>
    asyncio.run(run_migrations_online())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/migrations/env.py", line 88, in run_migrations_online
    engine = DB.engine_async()
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/app/db/__init__.py", line 34, in engine_async
    cls.set_db()
  File "/tmp/venv/lib/python3.10/site-packages/fractal_server/app/db/__init__.py", line 68, in set_db
    cls._engine_async = create_async_engine(
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/ext/asyncio/engine.py", line 43, in create_async_engine
    sync_engine = _create_engine(*arg, **kw)
  File "<string>", line 2, in create_engine
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 660, in create_engine
    event.listen(pool, "connect", on_connect)
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/event/api.py", line 115, in listen
    _event_key(target, identifier, fn).listen(*args, **kw)
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/event/registry.py", line 232, in listen
    self.dispatch_target.dispatch._listen(self, *args, **kw)
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/pool/events.py", line 69, in _listen
    event_key.base_listen(**kw)
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/event/registry.py", line 270, in base_listen
    for_modify._set_asyncio()
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/event/attr.py", line 265, in _set_asyncio
    self._exec_once_mutex = AsyncAdaptedLock()
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/util/concurrency.py", line 67, in AsyncAdaptedLock
    _not_implemented()
  File "/tmp/venv/lib/python3.10/site-packages/sqlalchemy/util/concurrency.py", line 47, in _not_implemented
    raise ValueError(
ValueError: the greenlet library is required to use this function. No module named 'greenlet'

@tcompa tcompa merged commit 216acfc into main Oct 17, 2023
@tcompa tcompa deleted the 894-remove-greenlet-dependency-and-add-asyncio-extra-to-sqlalchemy branch October 17, 2023 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove greenlet dependency, and add asyncio extra to sqlalchemy
3 participants