From: Daniele Varrazzo Date: Wed, 8 Jun 2022 13:18:29 +0000 (+0200) Subject: test: print notifications received in pipeline demo X-Git-Tag: 3.1~64^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9331d4abe924e54ec8919bc709c2440400118dcd;p=thirdparty%2Fpsycopg.git test: print notifications received in pipeline demo Investigating on the conditions causing the messages reported in #314. --- diff --git a/tests/scripts/pipeline-demo.py b/tests/scripts/pipeline-demo.py index e830c792b..9035911e3 100644 --- a/tests/scripts/pipeline-demo.py +++ b/tests/scripts/pipeline-demo.py @@ -19,7 +19,7 @@ from psycopg import pq, waiting from psycopg import errors as e from psycopg.abc import PipelineCommand from psycopg.generators import pipeline_communicate -from psycopg.pq._enums import Format +from psycopg.pq import Format, DiagnosticField from psycopg._compat import Deque psycopg_logger = logging.getLogger("psycopg") @@ -34,6 +34,19 @@ class LoggingPGconn: self._pgconn = pgconn self._logger = logger + def log_notice(result: pq.abc.PGresult) -> None: + def get_field(field: DiagnosticField) -> Optional[str]: + value = result.error_field(field) + return value.decode("utf-8", "replace") if value else None + + logger.info( + "notice %s %s", + get_field(DiagnosticField.SEVERITY), + get_field(DiagnosticField.MESSAGE_PRIMARY), + ) + + pgconn.notice_handler = log_notice + if args.trace: self._trace_file = open(args.trace, "w") pgconn.trace(self._trace_file.fileno())