[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 (7f14631fe8) 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) <xmo@odoo.com>
This commit is contained in:
+4
-5
@@ -130,11 +130,10 @@ def exec_pg_command(name, *args):
|
||||
warnings.warn("Since 16.0, use `subprocess` directly.", DeprecationWarning, stacklevel=2)
|
||||
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):
|
||||
warnings.warn("Since 16.0, use `subprocess` directly.", DeprecationWarning, stacklevel=2)
|
||||
|
||||
Reference in New Issue
Block a user