From 5cbb0738be13defdc0b2c63f09eb67dc927424f9 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Tue, 4 Apr 2023 12:41:24 +0000 Subject: [PATCH] [IMP] sql_db: allow to customize pg connection's application_name This is an improvement over commit f6c13d7 in order to allow full customization of postgresql connection's `application_name`. In a PID linux namespace the containers processes IDs might not be relevant for a system administrator and one might want to customize the content of the `application_name` just like it was possible to do before commit f6c13d7 using the `PGAPPNAME` environment variable. This commit allows to expose an `ODOO_PGAPPNAME` environment variable whose content will be interpolated with the PID (optional) closes odoo/odoo#117921 X-original-commit: a4108eee91f8e9bf82be5a4be4b91bab16baa0df Signed-off-by: Olivier Dony (odo) --- odoo/sql_db.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/odoo/sql_db.py b/odoo/sql_db.py index ea2feafb6b2..639e5174496 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -725,7 +725,11 @@ def connection_info_for(db_or_uri): :param str db_or_uri: database name or postgres dsn :rtype: (str, dict) """ - app_name = "odoo-%d" % os.getpid() + if 'ODOO_PGAPPNAME' in os.environ: + # Using manual string interpolation for security reason and trimming at default NAMEDATALEN=63 + app_name = os.environ['ODOO_PGAPPNAME'].replace('{pid}', str(os.getpid()))[0:63] + else: + app_name = "odoo-%d" % os.getpid() if db_or_uri.startswith(('postgresql://', 'postgres://')): # extract db from uri us = urls.url_parse(db_or_uri)