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

fix(django): catch the right error when trying to close db connection #9392

Merged
merged 2 commits into from
Dec 25, 2024

Conversation

Lotram
Copy link
Contributor

@Lotram Lotram commented Oct 31, 2024

Description

Fixes #9310
As explained in the issue, _maybe_close_db_fd tries to catch django's db-agnostic errors (such as django.db.InterfaceError), but _maybe_close_fd raises a db-specific error (eg. pyscog2.InterfaceError).

To fix that, we wrap the call to _maybe_close_fd with the c.wrap_database_errors context manager (cf here), made for this exact purpose. It prevents the worker to keep raising errors when initializing a process

This can easily be reproduced:

from django.db import connections
from celery import Celery
app = Celery("proj", broker="redis://localhost")
worker = app.Worker()

connection = connections.all()[0]
connection.connect()
connection.connection.close()  # for any reason, connection is closed

worker.start()

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.24%. Comparing base (49f8f71) to head (5ab931e).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
celery/fixups/django.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9392      +/-   ##
==========================================
+ Coverage   78.23%   78.24%   +0.01%     
==========================================
  Files         153      153              
  Lines       19039    19040       +1     
  Branches     2520     2520              
==========================================
+ Hits        14895    14898       +3     
+ Misses       3858     3854       -4     
- Partials      286      288       +2     
Flag Coverage Δ
unittests 78.22% <75.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Lotram
Copy link
Contributor Author

Lotram commented Oct 31, 2024

I don't really understand why Codecov is complaining, as the line I added is tested. And why are all the import lines considered as not tested ?

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please increase test coverage for the proposed change please?

@Lotram
Copy link
Contributor Author

Lotram commented Nov 2, 2024

I'll try to improve the coverage, but I don't get why codecov is complaining, thz line I added is tested, and the only line it's highligting is the function definition

@Lotram
Copy link
Contributor Author

Lotram commented Nov 3, 2024

@auvipy I honestly don't know how to improve the coverage, by looking at the report, only the function signatures are not covered. Isn't there a problem with the codecov configuration ?

@Lotram
Copy link
Contributor Author

Lotram commented Nov 3, 2024

@auvipy it's seems related to this pytest-cov issue.

@auvipy auvipy requested a review from a team November 3, 2024 15:05
@Lotram
Copy link
Contributor Author

Lotram commented Nov 21, 2024

Hey @auvipy do you have any news about this ? Are you waiting for the v5.5.0 to be released ?

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check the smoke test failures. it should be good addition to v5.5

@Nusnus
Copy link
Member

Nusnus commented Dec 17, 2024

we need to check the smoke test failures.

Fixed!

Copy link
Member

@Nusnus Nusnus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Nusnus
Copy link
Member

Nusnus commented Dec 17, 2024

@auvipy I’d like to merge this before the next RC, do you mind giving it a quick look please?
We need your approval to continue my friend.

@auvipy
Copy link
Member

auvipy commented Dec 25, 2024

Sure

@auvipy auvipy merged commit 7315c43 into celery:main Dec 25, 2024
69 of 70 checks passed
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.

_maybe_close_db_fd in Django fixups does not correctly handle all exceptions
3 participants