From eece396b3009dd50a712b9b68ace74a7ba6f6ba7 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Wed, 14 May 2025 14:05:29 +0530 Subject: [PATCH] Fixed an issue where the PSQL tool would hang when the database encoding was set to SQL_ASCII and certain commands were executed. --- docs/en_US/release_notes_9_4.rst | 1 + web/pgadmin/tools/psql/__init__.py | 9 ++++++++- web/pgadmin/utils/driver/psycopg3/typecast.py | 16 +++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/en_US/release_notes_9_4.rst b/docs/en_US/release_notes_9_4.rst index 120845fc1..4f1339140 100644 --- a/docs/en_US/release_notes_9_4.rst +++ b/docs/en_US/release_notes_9_4.rst @@ -31,6 +31,7 @@ Bug fixes ********* | `Issue #6564 `_ - Fix the issue where an error is displayed when a table is dropped while a query is running. + | `Issue #6968 `_ - Fixed an issue where the options key was not working as expected in the PSQL tool. | `Issue #8595 `_ - Enhance contrast for selected and hovered items in the Object Explorer to improve visibility and accessibility. | `Issue #8607 `_ - Fixed an issue where the query tool returns "cannot unpack non-iterable Response object" when running any query with a database name change. | `Issue #8608 `_ - Handle result grid data changes in View/Edit Data mode by automatically reconnecting to the server if a disconnection occurs. diff --git a/web/pgadmin/tools/psql/__init__.py b/web/pgadmin/tools/psql/__init__.py index 9ac05f89f..ca96fcad6 100644 --- a/web/pgadmin/tools/psql/__init__.py +++ b/web/pgadmin/tools/psql/__init__.py @@ -205,9 +205,16 @@ def read_terminal_data(parent, data_ready, max_read_bytes, sid): if parent in data_ready: # Read the output from parent fd (terminal). output = os.read(parent, max_read_bytes) + try: + decode_data = output.decode() + except Exception: + try: + decode_data = output.decode('UTF-8') + except Exception: + decode_data = output.decode('UTF-8', errors='replace') sio.emit('pty-output', - {'result': output.decode(), + {'result': decode_data, 'error': False}, namespace='/pty', room=sid) diff --git a/web/pgadmin/utils/driver/psycopg3/typecast.py b/web/pgadmin/utils/driver/psycopg3/typecast.py index eddcf8313..b96084fd9 100644 --- a/web/pgadmin/utils/driver/psycopg3/typecast.py +++ b/web/pgadmin/utils/driver/psycopg3/typecast.py @@ -246,10 +246,12 @@ class TextLoaderpgAdmin(TextLoader): return bytes(data).decode(python_encoding) return data.decode(python_encoding) except Exception: - if isinstance(data, memoryview): - return bytes(data).decode('UTF-8') - return data.decode('UTF-8') - else: - if isinstance(data, memoryview): - return bytes(data).decode('ascii', errors='replace') - return data.decode('ascii', errors='replace') + try: + if isinstance(data, memoryview): + return bytes(data).decode('UTF-8') + return data.decode('UTF-8') + except Exception: + if isinstance(data, memoryview): + return bytes(data).decode('ascii', + errors='replace') + return data.decode('ascii', errors='replace')