From a1408aff2d17808303d35c4806a9d5f4fa61cb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez?= Date: Tue, 29 Jan 2019 22:48:45 +0000 Subject: [PATCH] [FIX] profiler: Open form view without errors if the users is not superadmin for psql MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Moisés López --- profiler/models/profiler_profile.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/profiler/models/profiler_profile.py b/profiler/models/profiler_profile.py index 82bbf8d34..cac78e23b 100644 --- a/profiler/models/profiler_profile.py +++ b/profiler/models/profiler_profile.py @@ -71,7 +71,10 @@ class ProfilerProfile(models.Model): @api.model def _find_loggers_path(self): - self.env.cr.execute("SHOW log_directory") + try: + self.env.cr.execute("SHOW log_directory") + except ProgrammingError: + return log_directory = self.env.cr.fetchone()[0] self.env.cr.execute("SHOW log_filename") log_filename = self.env.cr.fetchone()[0] @@ -123,12 +126,16 @@ class ProfilerProfile(models.Model): def onchange_enable_postgresql(self): if not self.enable_postgresql: return - self.env.cr.execute("SHOW config_file") - pg_config_file = self.env.cr.fetchone()[0] + try: + self.env.cr.execute("SHOW config_file") + except ProgrammingError: + pg_config_file = None + else: + pg_config_file = self.env.cr.fetchone()[0] db_host = tools.config.get('db_host') if db_host == 'localhost' or db_host == '127.0.0.1': db_host = False - if db_host: + if db_host and pg_config_file: pg_config_file = 'postgres@%s:%s' % (db_host, pg_config_file) self.pg_remote = db_host @@ -308,7 +315,10 @@ export PGOPTIONS="-c log_min_duration_statement=0 \\ except IOError: self.description += ( "\nInstall 'apt-get install pgbadger'") + return try: + if not self.pg_log_path: + raise IOError with open(self.pg_log_path, "r"): pass except IOError: @@ -316,7 +326,7 @@ export PGOPTIONS="-c log_min_duration_statement=0 \\ "\nCheck if exists and has permission to read the log file." "\nMaybe running: chmod 604 '%s'" ) % self.pg_log_path - + return pgbadger_cmd = [ pgbadger_bin, '-f', 'stderr', '--sample', '15', '-o', '-', '-x', 'html', '--quiet',