#25329: _nodb_connection is open for an entire test suite run -------------------------------------+------------------------------------- Reporter: mewtaylor | Owner: nobody Type: Bug | Status: new Component: Testing framework | Version: master Severity: Normal | Resolution: Keywords: nodb, testing, test | Triage Stage: Accepted runner | Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by mewtaylor): Replying to [comment:1 jarshwah]: > How certain are you that the nodb connection is to blame? I'm relatively certain – I also ran a trace on the tear down method to verify that it was looking at the right name for the test database, and it was. When I investigated the source of {{{BaseDatabaseCreation}}} further I saw that both {{{_create_test_db()}}} and {{{_destroy_test_db()}}} use a nodb connection – for create, it uses the line {{{with self._nodb_connection.cursor() as cursor}}}, whereas for destroy, it uses the line {{{with self.connection._nodb_connection.cursor() as cursor}}}. I believe they are retrieving the same connection each time, because even though create uses the property on BaseDatabaseCreation itself, that property appears to return {{{self.connection._nodb_connection}}} (see [https://github.com/django/django/blob/master/django/db/backends/base/creation.py#L24-L29 here]). And, since {{{self.connection}}} is set on init, that was what made me think it was possible that the connection was being kept open for the entire time. Also it appears to be a [https://github.com/django/django/blob/master/django/db/backends/base/base.py#L571-L586 cached_property] on the connection object too. > > I think that if the nodb connection can be safely closed, then it should be closed. It can be created again to tear down the test database if it's needed. Is the nodb connection used after test database creation other than for tear down? I'm not 100% sure. Inside of {{{BaseDatabaseCreation}}} it doesn't appear to be used anywhere else. A cursory search of the repo didn't reveal it being used elsewhere, though. -- Ticket URL: <https://code.djangoproject.com/ticket/25329#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.d702a88ef4193d696cd81b4cd0500d72%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.