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

UP024 removes non-OSError exception #3422

Closed
charliermarsh opened this issue Mar 9, 2023 · 0 comments · Fixed by #3451
Closed

UP024 removes non-OSError exception #3422

charliermarsh opened this issue Mar 9, 2023 · 0 comments · Fixed by #3451
Assignees
Labels
bug Something isn't working

Comments

@charliermarsh
Copy link
Member

Found a false positive one:

My code:

import socket
...
from kombu import Connection, exceptions

...

try:
    conn = Connection(settings.CELERY_BROKER_URL)
    conn.ensure_connection(max_retries=2)
    conn._close()
except (socket.error, exceptions.OperationalError):
    return HttpResponseServerError("cache: cannot connect to broker.")

their MROs:

exceptions.OperationalError.__mro__
(<class 'kombu.exceptions.OperationalError'>, <class 'kombu.exceptions.KombuError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)

socket.error.__mro__
(<class 'OSError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)

ruff suggests:

try:
    conn = Connection(settings.CELERY_BROKER_URL)
    conn.ensure_connection(max_retries=2)
    conn._close()
except OSError:
    return HttpResponseServerError("cache: cannot connect to broker.")

Seems like ruff ignores the second one's MRO. Thank you!

Originally posted by @deliro in #1568 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant