Comment (by Scott Macpherson):
I'd be happy to. Are you able to give me some pointers on replicating the
behaviour we're seeing from inside `TestCase`?
I've been mucking about with `TransactionTestCase` rather than `TestCase`,
and I can get things into a state where `connection.connection` inside
`mogrify` returns an idle connection rather than one that's in a
transaction, but that's not far enough to replicate this.
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Mariusz Felisiak):
Replying to [comment:8 Scott Macpherson]:
> I'd be happy to. Are you able to give me some pointers on replicating
the behaviour we're seeing from inside `TestCase`?
>
> I've been mucking about with `TransactionTestCase` rather than
`TestCase`, and I can get things into a state where
`connection.connection` inside `mogrify` returns an idle connection rather
than one that's in a transaction, but that's not far enough to replicate
this.
Since the real issue is in `compose_sql()`, I'd add a backend-specific
test, e.g.
{{{#!diff
diff --git a/tests/backends/postgresql/tests.py
b/tests/backends/postgresql/tests.py
index 9c4512be24..82df344139 100644
--- a/tests/backends/postgresql/tests.py
+++ b/tests/backends/postgresql/tests.py
@@ -420,3 +420,11 @@ class Tests(TestCase):
with self.assertRaisesMessage(NotSupportedError, msg):
connection.check_database_version_supported()
self.assertTrue(mocked_get_database_version.called)
+
+ def test_compose_sql_no_connection(self):
+ new_connection = connection.copy()
+ # compose_sql() should open a new connection.
+ try:
+ self.assertEqual(new_connection.ops.compose_sql("SELECT %s",
["test"]), "SELECT 'test'")
+ finally:
+ new_connection.close()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:9>
* owner: (none) => Scott Macpherson
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:10>
Comment (by Scott Macpherson):
Thanks for your help - you made it too easy! Pull request 16760 created:
https://github.com/django/django/pull/16760.
`backends.postgres` has one new regression test - that suite had one skip
before and the same skip after this change. `tests.postgres_tests`
produces the same output before and after this change as well.
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:11>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:12>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:13>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"53aee470d5b35e2708864d5221d2b5655e10c091" 53aee470]:
{{{
#!CommitTicketReference repository=""
revision="53aee470d5b35e2708864d5221d2b5655e10c091"
Fixed #34486 -- Fixed DatabaseOperations.compose_sql() crash with no
existing database connection on PostgreSQL.
Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:14>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"090d5ccc6c59e4df491ec0599c569834bdcf1409" 090d5cc]:
{{{
#!CommitTicketReference repository=""
revision="090d5ccc6c59e4df491ec0599c569834bdcf1409"
[4.2.x] Fixed #34486 -- Fixed DatabaseOperations.compose_sql() crash with
no existing database connection on PostgreSQL.
Regression in 09ffc5c1212d4ced58b708cbbf3dfbfb77b782ca.
Backport of 53aee470d5b35e2708864d5221d2b5655e10c091 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34486#comment:15>