]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- repair laziness about setting time zone here, which is leaking
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Oct 2015 16:00:39 +0000 (12:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Oct 2015 16:34:12 +0000 (12:34 -0400)
out depending on connection pool state

(cherry picked from commit 2a8a06e33af60705faf3e7601ec7b3e31e44f8fb)
(cherry picked from commit 48ad282e379d49cf6d6eb97dc0739fa0f29f5464)

Conflicts:
test/dialect/postgresql/test_query.py

test/dialect/postgresql/test_query.py

index a512b56fa01350f625887fc081e2e7afbb7e17d0..42cb6699ae1bb8806e1b4714c0eb4e7d5d4201ac 100644 (file)
@@ -793,6 +793,19 @@ class ExtractTest(fixtures.TablesTest):
     run_inserts = 'once'
     run_deletes = None
 
+    @classmethod
+    def setup_bind(cls):
+        from sqlalchemy import event
+        eng = engines.testing_engine()
+
+        @event.listens_for(eng, "connect")
+        def connect(dbapi_conn, rec):
+            cursor = dbapi_conn.cursor()
+            cursor.execute("SET SESSION TIME ZONE 0")
+            cursor.close()
+
+        return eng
+
     @classmethod
     def define_tables(cls, metadata):
         Table('t', metadata,
@@ -813,19 +826,15 @@ class ExtractTest(fixtures.TablesTest):
             def utcoffset(self, dt):
                 return datetime.timedelta(hours=4)
 
-        conn = testing.db.connect()
-
-        # we aren't resetting this at the moment but we don't have
-        # any other tests that are TZ specific
-        conn.execute("SET SESSION TIME ZONE 0")
-        conn.execute(
+        cls.bind.execute(
             cls.tables.t.insert(),
             {
                 'dtme': datetime.datetime(2012, 5, 10, 12, 15, 25),
                 'dt': datetime.date(2012, 5, 10),
                 'tm': datetime.time(12, 15, 25),
                 'intv': datetime.timedelta(seconds=570),
-                'dttz': datetime.datetime(2012, 5, 10, 12, 15, 25, tzinfo=TZ())
+                'dttz': datetime.datetime(2012, 5, 10, 12, 15, 25,
+                                          tzinfo=TZ())
             },
         )
 
@@ -853,7 +862,7 @@ class ExtractTest(fixtures.TablesTest):
             fields.update(overrides)
 
         for field in fields:
-            result = testing.db.scalar(
+            result = self.bind.scalar(
                 select([extract(field, expr)]).select_from(t))
             eq_(result, fields[field])
 
@@ -869,7 +878,7 @@ class ExtractTest(fixtures.TablesTest):
     def test_three(self):
         t = self.tables.t
 
-        actual_ts = testing.db.scalar(func.current_timestamp()) - \
+        actual_ts = self.bind.scalar(func.current_timestamp()) - \
             datetime.timedelta(days=5)
         self._test(func.current_timestamp() - datetime.timedelta(days=5),
                    {"hour": actual_ts.hour, "year": actual_ts.year,
@@ -918,7 +927,7 @@ class ExtractTest(fixtures.TablesTest):
 
     def test_twelve(self):
         t = self.tables.t
-        actual_ts = testing.db.scalar(
+        actual_ts = self.bind.scalar(
             func.current_timestamp()).replace(tzinfo=None) - \
             datetime.datetime(2012, 5, 10, 12, 15, 25)