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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Lotram
Copy link

@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.17%. Comparing base (4d129fd) to head (ed6708c).

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.15%   78.17%   +0.01%     
==========================================
  Files         153      153              
  Lines       19029    19030       +1     
  Branches     2518     2518              
==========================================
+ Hits        14873    14876       +3     
+ Misses       3867     3863       -4     
- Partials      289      291       +2     
Flag Coverage Δ
unittests 78.15% <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
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
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
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
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
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 ?

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
2 participants