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

Pytest-django , factory_boy InterfaceError: connection already closed #835

Closed
PyB1l opened this issue Apr 16, 2020 · 5 comments
Closed

Pytest-django , factory_boy InterfaceError: connection already closed #835

PyB1l opened this issue Apr 16, 2020 · 5 comments

Comments

@PyB1l
Copy link

PyB1l commented Apr 16, 2020

Failed tests occur when running multiple tests that use @django_db or / and @django_db(transaction=True) complaining that connection is already closed.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <django.db.backends.postgresql.base.DatabaseWrapper object at 0x7f082a459a90>
name = None

    @async_unsafe
    def create_cursor(self, name=None):
        if name:
            # In autocommit mode, the cursor will be used outside of a
            # transaction, hence use a holdable cursor.
            cursor = self.connection.cursor(name, scrollable=False, withhold=self.connection.autocommit)
        else:
>           cursor = self.connection.cursor()
E           django.db.utils.InterfaceError: connection already closed

On the other sode,running the single test that failed alone, works as expected. Affected version are:

Python 3.7
Django 3.0
pytest 5.4.1
pytest-cov 2.8.1
pytest-django 3.9.0
pytest-factoryboy 2.0.3
pytest-forked 1.1.3

@PyB1l
Copy link
Author

PyB1l commented Apr 17, 2020

I need to mention that not all tests fail. It ONLY breaks a random test with django.db.utils.InterfaceError: connection already closed 8 of 10 times. In some rare cases it passes all tests. Could it be something about Python3.7+ specific issue? I never had any similar issues in python 3.6

@bluetech
Copy link
Member

Hi @PyB1l,

Given that you are aware of #824 and it didn't fix the issue, if you can create a repo with a minimal reproduction (i.e. least amount of dependencies and code), that would be helpful.

@PyB1l
Copy link
Author

PyB1l commented Apr 17, 2020

I am inspecting the test suite in Django 3.0.5 right now and it seems to has no issue, there, with the latest plugins. I will do more research and i will come back with results before i create a test project.

@PyB1l
Copy link
Author

PyB1l commented Apr 17, 2020

BTW the issue i run into was detected in Django 3.0.2.

@PyB1l
Copy link
Author

PyB1l commented Apr 17, 2020

Ok it definitely seems to be ok with Django, pytest, pytest-django, factory_boy latest version. I will close this for now and if i find any results i will come back.

@PyB1l PyB1l closed this as completed Apr 17, 2020
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

No branches or pull requests

2 participants