-
Notifications
You must be signed in to change notification settings - Fork 55
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
Error on teardown of test database in Django integration test #1106
Comments
It's more complicated than I thought. I also run some async stuff in my sync task, and this error doesn't seem to purely depend on Procrastinate. I will close this for now and investigate it further. Also, our mix of sync and async stuff really bites us quite often 🙄. |
I investigated this a bit further. The above error happens as soon as I do a database access in the task, e.g.: @app.task
def example_task():
job = ProcrastinateJob.objects.first()
assert job is not None Also when using async tasks, e.g.: @app.task
async def example_task_async():
job = await ProcrastinateJob.objects.afirst()
assert job is not None A simple workaround is to close the database connection at the end of a task manually by calling Maybe we should add a hint about this to the documentation. That's why I reopen this issue. |
This looks like we might be able to make a reproducing test in procrastinate's own codebase ? |
Sure, I can add an integration test. It won't fail; pytest just provides it as a warning, but it will be visible on the console. |
You can turn that warning into an error with @pytest.mark.filterwarnings (you can use filterwarning for the whole testsuite but in this cas we probably want to do it only for the specific tests that handle this) |
Just to keep you informed, it is not reproducible in Procrastinate itself, but we use a slightly different setup (Django 5, Psycopg 3). I will set up a minimal Django 5 project with Procrastinate in the upcoming days and see if I can reproduce it there, but I have the feeling there's nothing Procrastinate can do about it. I will keep you updated, and eventually close the issue again. |
When running an integration (sync) test using Pytest in Django I end up with a warning that another session is using the database:
This happens as soon as I run the worker, as mentioned in the documentation:
It seems the worker leaves some connections open. I tried calling
app.close()
explicitly at the end of the test, but this also doesn't help.The text was updated successfully, but these errors were encountered: