PostgreSQL shouldn't roll back SET TIME ZONE, even if the first transaction is rolled back (#17062).
(self)
| 183 | self.assertNotIn("service", params) |
| 184 | |
| 185 | def test_connect_and_rollback(self): |
| 186 | """ |
| 187 | PostgreSQL shouldn't roll back SET TIME ZONE, even if the first |
| 188 | transaction is rolled back (#17062). |
| 189 | """ |
| 190 | new_connection = no_pool_connection() |
| 191 | try: |
| 192 | # Ensure the database default time zone is different than |
| 193 | # the time zone in new_connection.settings_dict. We can |
| 194 | # get the default time zone by reset & show. |
| 195 | with new_connection.cursor() as cursor: |
| 196 | cursor.execute("RESET TIMEZONE") |
| 197 | cursor.execute("SHOW TIMEZONE") |
| 198 | db_default_tz = cursor.fetchone()[0] |
| 199 | new_tz = "Europe/Paris" if db_default_tz == "UTC" else "UTC" |
| 200 | new_connection.close() |
| 201 | |
| 202 | # Invalidate timezone name cache, because the setting_changed |
| 203 | # handler cannot know about new_connection. |
| 204 | del new_connection.timezone_name |
| 205 | |
| 206 | # Fetch a new connection with the new_tz as default |
| 207 | # time zone, run a query and rollback. |
| 208 | with self.settings(TIME_ZONE=new_tz): |
| 209 | new_connection.set_autocommit(False) |
| 210 | new_connection.rollback() |
| 211 | |
| 212 | # Now let's see if the rollback rolled back the SET TIME ZONE. |
| 213 | with new_connection.cursor() as cursor: |
| 214 | cursor.execute("SHOW TIMEZONE") |
| 215 | tz = cursor.fetchone()[0] |
| 216 | self.assertEqual(new_tz, tz) |
| 217 | |
| 218 | finally: |
| 219 | new_connection.close() |
| 220 | |
| 221 | def test_connect_non_autocommit(self): |
| 222 | """ |
nothing calls this directly
no test coverage detected