celery / kombu

Messaging library for Python.
http://kombu.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
2.88k stars 928 forks source link

AttributeError due to improperly specified dependency #1644

Open atleta opened 1 year ago

atleta commented 1 year ago

5.2.4, as of now, throws an Attribute error when I try to run my (django) app:

  File ".../project/root_package/__init__.py", line 5, in <module>
    from .celery import app as celery_app
  File ".../project/root_package/celery.py", line 9, in <module>
    from raven.contrib.celery import register_logger_signal, register_signal
  File ".../project/env/lib/python3.7/site-packages/raven/contrib/celery/__init__.py", line 13, in <module>
    from celery.signals import (
  File ".../project/env/lib/python3.7/site-packages/celery/signals.py", line 14, in <module>
    from .utils.dispatch import Signal
  File ".../project/env/lib/python3.7/site-packages/celery/utils/__init__.py", line 16, in <module>
    from .nodenames import nodename, nodesplit, worker_direct
  File ".../project/env/lib/python3.7/site-packages/celery/utils/nodenames.py", line 6, in <module>
    from kombu.entity import Exchange, Queue
  File ".../project/env/lib/python3.7/site-packages/kombu/entity.py", line 7, in <module>
    from .serialization import prepare_accept_content
  File ".../project/env/lib/python3.7/site-packages/kombu/serialization.py", line 440, in <module>
    for ep, args in entrypoints('kombu.serializers'):  # pragma: no cover
  File ".../project/env/lib/python3.7/site-packages/kombu/utils/compat.py", line 82, in entrypoints
    for ep in importlib_metadata.entry_points().get(namespace, [])
AttributeError: 'EntryPoints' object has no attribute 'get'

The reason apparently is that importlib_metadata has released v 6.0.0 which changed the API and broke Kombu. Celery has a similar bug last April. These kind of bugs will keep popping up until you specify not just the minimum but also the maximum version for your dependencies. Please consider pinning all your dependencies with a maximum version number too.

open-collective-bot[bot] commented 1 year ago

Hey @atleta :wave:, Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider backing us - every little helps!

We also offer priority support for our sponsors. If you require immediate assistance please consider sponsoring us.

auvipy commented 1 year ago

https://github.com/celery/kombu/pull/1601 should fix this already

atleta commented 1 year ago

@auvipy No, it doesn't. It does fix the code, that was broken by the change in the dependency, it does not fix the problem. Next time there is a breaking change importlib_metadata (or any other dependency) the same thing will happen. You can't claim that your code is compatible with all future versions of your dependencies, but this is what you do when you only specify a minimum version requirement.

The problem is actually even worse than this: if someone pins a specific version of kombu (or, more likely, celery) and there is a breaking change in the dependencies a few releases down the line, then they are screwed, because they won't be able to upgrade. Of course, everyone can debug it themselves and figure out which version to pin the dependency at, but wouldn't it be simpler if the project maintainers did it?

In this case, the maintainer of importlib_metadata claims that this specific API has been depricated for 1.5 years, with the code printing warnings. (Though it would have probably been better if it stated the version it will be removed in because that may have maybe inspired you to use it in the pin.)

auvipy commented 1 year ago

you are welcome to contribute a fix you think better

atleta commented 1 year ago

Thanks for the detailed answer. Thoughtfull but compact responses like this, packed with arguments prove that it's worth giving detailed feedback and suggestions then extend it with further explanations if one feels that they weren't able to put all the details into the original report.

This also gives me sufficient trust that my contribution will be accepted, so I'll clone the project and add the missing 5 or so characters.

auvipy commented 1 year ago

I will be happy to review you PR and merge within reasonable time frame.