[devtools] add has_cache for postgres (closes #5739624)

devtools stores info about existing dbs in the db handler, but in the case of postgresql that doesn't take into account the path to the cluster's datadir. Which means if we run two test modules (in the same test run), we'll create a "__default_empty_db__" for the first one, cache its existence, and then when moving on to the other module, believe the template already exists (but since the datadir depends on the test module's path, it does not). This patch is a bit of a kludge, and it would be better to make the cache key include enough data to not need this, but I'm not sure how to do that.

authorJulien Cristau <julien.cristau@logilab.fr>
changesetc43e5dc41f8b
branchdefault
phasepublic
hiddenno
parent revision#cfded6d0da11 fix bad-caching of datetime with tz info at sql generation time
child revision#57c60a96de70 [migration] fix change_attribute_type to update the live schema
files modified by this revision
devtools/__init__.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1437724628 -7200
# Fri Jul 24 09:57:08 2015 +0200
# Node ID c43e5dc41f8bd9062f00875dd8872fa3d18dabbd
# Parent cfded6d0da116ddd7dc1aadbd5baf3957ddd2b35
[devtools] add has_cache for postgres (closes #5739624)

devtools stores info about existing dbs in the db handler, but in the
case of postgresql that doesn't take into account the path to the
cluster's datadir. Which means if we run two test modules (in the same
test run), we'll create a "__default_empty_db__" for the first one,
cache its existence, and then when moving on to the other module,
believe the template already exists (but since the datadir depends on
the test module's path, it does not). This patch is a bit of a kludge,
and it would be better to make the cache key include enough data to not
need this, but I'm not sure how to do that.

diff --git a/devtools/__init__.py b/devtools/__init__.py
@@ -625,10 +625,15 @@
1          backup_name = self._backup_name(db_id)
2          if backup_name in self.helper.list_databases(self.cursor):
3              return backup_name
4          return None
5 
6 +    def has_cache(self, db_id):
7 +        backup_name = self._backup_name(db_id)
8 +        return (super(PostgresTestDataBaseHandler, self).has_cache(db_id)
9 +                and backup_name in self.helper.list_databases(self.cursor))
10 +
11      def init_test_database(self):
12          """initialize a fresh postgresql database used for testing purpose"""
13          from cubicweb.server import init_repository
14          from cubicweb.server.serverctl import system_source_cnx, createdb
15          # connect on the dbms system base to create our base