Flower: Upgrading to Celery 5.0.0 breaks flower due to change in celery.bin.base module.

Created on 25 Sep 2020  路  42Comments  路  Source: mher/flower

If you run flower with Celery 5.0.0 or if you use the docker image, it will say it cannot import "Command".

Steps to reproduce the behavior:

  1. pip install celery==5.0.0
    THEN
  2. flower --version
    OR
  3. flower -A proj --broker=redis://redis
    OR
  4. flower

image

The Command class is no longer part of the base module:
https://docs.celeryproject.org/en/v5.0.0/reference/celery.bin.base.html

Which means it can no longer import and inherit Command:

```command.py
from __future__ import absolute_import
from __future__ import print_function

import os
import sys
import atexit
import signal
import logging

from pprint import pformat

from logging import NullHandler

from tornado.options import options
from tornado.options import parse_command_line, parse_config_file
from tornado.log import enable_pretty_logging
from celery.bin.base import Command

from . import __version__
from .app import Flower
from .urls import settings
from .utils import abs_path, prepend_url
from .options import DEFAULT_CONFIG_FILE, default_options

logger = logging.getLogger(__name__)

class FlowerCommand(Command):
# ...
```

bug

Most helpful comment

This issue should not be closed because not solved

Regards

All 42 comments

Same problem here

Same problem here as well

Same problem here also.

Same for me, needed downgrade to 4.4.7

Same here, also had to downgrade sadly

Same for me, dowgraded celery to 4.4.7 as @packetflow

Same problem for me

Hello All,

A work around if you don't want to downgrade all of celery is to use a docker container for flower:

  flower:
    image: mher/flower
    command: ["--app your_app", "--url_prefix=flower", "--broker=redis://redis"]
    ports:
      - 5555:5555
    restart: unless-stopped

Why was the issue closed? Is this resolved?

This issue should not be closed because not solved

Regards

@mbayabo @mher Please keep one of the #1031 or #1029 open.

@mbayabo @mher Please keep one of the #1031 or #1029 open.

I didn't close this.

@mbayabo I guess you accidentally clicked the "close and comment" button https://github.com/mher/flower/issues/1029#event-3837160460 but you should be able to re-open this issue.

@chrisburr Oh I see.

Same problem for me, even using the docker image. Should I use a specific tag?

Hello All,

A work around if you don't want to downgrade all of celery is to use a docker container for flower:

  flower:
    image: mher/flower
    command: ["--app your_app", "--url_prefix=flower", "--broker=redis://redis"]
    ports:
      - 5555:5555
    restart: unless-stopped

I solved creating a custom docker image in which I install flower and celery (version 4.4.7) using pip and then using my docker image.

FROM python:3.8.2-slim-buster

RUN apt-get update && apt-get install -y gcc python3-dev

RUN pip install --no-cache-dir -Iv flower redis celery==4.4.7

EXPOSE 5555

ENTRYPOINT ["flower"]

You can use 0.9.5 tag with docker image

You can use 0.9.5 tag with docker image

This one is working too. Thanks

You can use 0.9.5 tag with docker image

This gets around this issue but then we run into the permissions issue if using persistent=True (which I think is fixed in latest). Any workaround besides creating another Dockerfile?

creating a docker image seems to connect but can't seem to access the GUI via localhost:5555 any clues?

edit:
tried the custom image suggested by @ale8193 but having the same issue, it seems to be running properly but can麓t access GUI

I have the same issue:

Traceback (most recent call last):
  File "/usr/local/bin/flower", line 5, in <module>
    from flower.__main__ import main
  File "/usr/local/lib/python3.9/site-packages/flower/__main__.py", line 4, in <module>
    from flower.command import FlowerCommand
  File "/usr/local/lib/python3.9/site-packages/flower/command.py", line 17, in <module>
    from celery.bin.base import Command
ImportError: cannot import name 'Command' from 'celery.bin.base' (/usr/local/lib/python3.9/site-packages/celery/bin/base.py)

when this problem can be solved

Any plan to fix this? Anyone working on this? Or should should I attempt a PR? Or give up on Flower and upgrade Celery to 5?

If u are using a custom docker django/celery image, u can just install celery<5 before launching flower. That's my current workaround 馃し

    command:
      - /bin/bash
      - -c
      - |
        pip install "celery<5"
        flower --app=pnk.celery:app --loglevel=warning --url_prefix=flower

It looks like they moved celery to use click.Command instead of celerys own implementation, so this will need to be ported to use one of the new implementations.

Have a look at the difference in celery/bin/base.py between master and the 4.3 tag.

I guess making it use CeleryCommand will be a start, then add the changes needed to make it work with click.

I think all you need to do is implementing a click-style CLI for the subcommand; check one of the core celery subcommands for an example.

That sounds good, it probably needs someone more familiar with the code than me, apart from just now I haven't used flower, or looked at the celery code for 5 years.

I think all you need to do is implementing a click-style CLI for the subcommand; check one of the core celery subcommands for an example.

I started looking at this, but it's a bit out of my depth without pre-existing familiarity with flower's codebase:

  • vine needs to be updated from 1.3.0 to 5.0.0
  • the command style is function based, and apparently incompatible with a class based approach
  • flower runs code outside of celery

Maybe I'll try again later, but I'm too unfamiliar with both click and flower to be useful here, as much as I need flower in my workflow.

Scratch what I just said, looks like celery has documented how to invoke flower, is that because someone's working on this already?

https://github.com/celery/celery/blob/master/docs/userguide/extending.rst#adding-new-program-celery-sub-commands

Looks like it's not even possible in celery 5.0.2 to use the click system as a celery plugin due to not having @with_plugins(iter_entry_points('celery.commands'))

I have the same issue working with celery 5.0.2

```Traceback (most recent call last):

File "/usr/local/bin/flower", line 5, in
from flower.__main__ import main
File "/usr/local/lib/python3.9/site-packages/flower/__main__.py", line 4, in
from flower.command import FlowerCommand
File "/usr/local/lib/python3.9/site-packages/flower/command.py", line 17, in
from celery.bin.base import Command
ImportError: cannot import name 'Command' from 'celery.bin.base' (/usr/local/lib/python3.9/site-packages/celery/bin/base.py)```

Same problem for me

Also getting this issue. This temp fix of using a downgraded version of celery in a custom Dockerfile isn't something I feel ok going to production with.

I agree with you, I hope to be able to remove this temporary fix as soon as possible

I am having the same issue!

Traceback (most recent call last):
  File "/home/talha/.local/share/virtualenvs/scaling-celery-6oDIcQ0v/bin/flower", line 5, in <module>
    from flower.__main__ import main
  File "/home/talha/.local/share/virtualenvs/scaling-celery-6oDIcQ0v/lib/python3.7/site-packages/flower/__main__.py", line 4, in <module>
    from flower.command import FlowerCommand
  File "/home/talha/.local/share/virtualenvs/scaling-celery-6oDIcQ0v/lib/python3.7/site-packages/flower/command.py", line 17, in <module>
    from celery.bin.base import Command
ImportError: cannot import name 'Command' from 'celery.bin.base' (/home/talha/.local/share/virtualenvs/scaling-celery-6oDIcQ0v/lib/python3.7/site-packages/celery/bin/base.py)

I also have same issue with celery > 4.4.7

+1

Hello, are you planning to develop a fix? I would be happy to help, but I still don't have the skills :-/

A PR is about to be merged https://github.com/mher/flower/pull/1021
We are looking forward testing it

Is this issue closed?

See the comment above your own.

A PR is about to be merged #1021
We are looking forward testing it

as mentioned by @tramora the current workaround is using the fork of @avikam

pip install https://github.com/avikam/flower/zipball/master#egg=flower

run with

flower -A myapp flower --basic_auth=user:pass

I don't know why celery -A myapp flower ... isn't working for me.

Was this page helpful?
0 / 5 - 0 ratings