From 083417f58364711a9382a5153382d8a7b647e085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 13 Feb 2026 13:33:41 +0100 Subject: [PATCH] [FIX] logging_json: forward compatibility (#510) Make the module compatible w/ ``python-json-logger==3.3.*`` (importing ``jsonlogger`` displays a deprecation warning) Co-authored-by: SilvioC2C <87646954+SilvioC2C@users.noreply.github.com> --- logging_json/json_log.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/logging_json/json_log.py b/logging_json/json_log.py index 91cf0bea..8c5821c0 100644 --- a/logging_json/json_log.py +++ b/logging_json/json_log.py @@ -6,17 +6,23 @@ import threading import uuid +import pythonjsonlogger + from odoo import http from .strtobool import strtobool _logger = logging.getLogger(__name__) -try: - from pythonjsonlogger import jsonlogger -except ImportError: +# Module ``jsonlogger`` of package ``python-json-logger`` is deprecated since version +# 3.1.0, keep it for backward compatibility +if hasattr(pythonjsonlogger, "json"): + jsonlogger = pythonjsonlogger.json +elif hasattr(pythonjsonlogger, "jsonlogger"): + jsonlogger = pythonjsonlogger.jsonlogger +else: jsonlogger = None # noqa - _logger.debug("Cannot 'import pythonjsonlogger'.") + _logger.debug("Cannot import 'json' or 'jsonlogger' from 'pythonjsonlogger'.") def is_true(strval):