Commit f2f98abb authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Avoided closing the database connection within a transaction.

Refs #9437.
parent b746f8a9
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -402,18 +402,10 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
        """
        Helper routine for calling PostGIS functions and returning their result.
        """
        cursor = self.connection._cursor()
        try:
            try:
                cursor.execute('SELECT %s()' % func)
                row = cursor.fetchone()
            except:
                # Responsibility of callers to perform error handling.
                raise
        finally:
        # Close out the connection.  See #9437.
            self.connection.close()
        return row[0]
        with self.connection.temporary_connection() as cursor:
            cursor.execute('SELECT %s()' % func)
            return cursor.fetchone()[0]

    def postgis_geos_version(self):
        "Returns the version of the GEOS library used with PostGIS."
+3 −1
Original line number Diff line number Diff line
@@ -472,11 +472,13 @@ class BaseDatabaseWrapper(object):
        Context manager that ensures that a connection is established, and
        if it opened one, closes it to avoid leaving a dangling connection.
        This is useful for operations outside of the request-response cycle.

        Provides a cursor: with self.temporary_connection() as cursor: ...
        """
        must_close = self.connection is None
        cursor = self.cursor()
        try:
            yield
            yield cursor
        finally:
            cursor.close()
            if must_close: