From fd4bc4d14d3ef4ce8e7f13b76effda54a43861fd Mon Sep 17 00:00:00 2001 From: Isaac Gallart Bochons Date: Wed, 22 Nov 2023 21:45:11 +0000 Subject: [PATCH] [FW][FIX] base: postgres subprocess error when dumping database When Odoo is installed with the latest version of the PostgreSQL client (postgres-client or postgres-client-16) and running in Docker (possibly other environments as well but not reproduced so far), executing `pg_dump` via `exec_pg_command` fails with Database backup error: Postgres subprocess ('/usr/bin/pg_dump', '--no-owner', '--file=/tmp/tmpmnqiktog/dump.sql', '15TEST') error 1 This seems to be because `os.devnull` is being opened in *read* mode which is incorrect (as it's written to). It's not entirely clear if older `pg_dump` simply ignored the non-writable stdout or if docker adds some restrictions which cause the failure. Either way this can be solved by either opening `os.devnull` in write mode or switching to the `DEVNULL` constant. While the function is deprecated in 16.0 (7f14631fe804ffdcc82d8b2fc1d2e70e485bf806) and removed in master (ae3056f3f4fca82c6aee69bf201532e14829c45e) the latter is not a huge change and it a touch cleaner. fixes #139687 closes odoo/odoo#143198 Forward-port-of: odoo/odoo#142987 Signed-off-by: Xavier Morel (xmo) --- openerp/tools/misc.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 96a95e48b782b..375506b1c44dd 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -117,11 +117,10 @@ def exec_pg_environ(): def exec_pg_command(name, *args): prog = find_pg_tool(name) env = exec_pg_environ() - with open(os.devnull) as dn: - args2 = (prog,) + args - rc = subprocess.call(args2, env=env, stdout=dn, stderr=subprocess.STDOUT) - if rc: - raise Exception('Postgres subprocess %s error %s' % (args2, rc)) + args2 = (prog,) + args + rc = subprocess.call(args2, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + if rc: + raise Exception('Postgres subprocess %s error %s' % (args2, rc)) def exec_pg_command_pipe(name, *args): prog = find_pg_tool(name)