Bug #119733 SyntaxWarning for DbMySQLSession.py:360
Submitted: 21 Jan 11:41 Modified: 21 Jan 16:42
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Open Impact on me:
None 
Category:Shell General / Core Client Severity:S2 (Serious)
Version:9.6.0 OS:Any
Assigned to: CPU Architecture:Any

[21 Jan 11:41] Daniël van Eeden
Description:
$ mysqlsh mysql://root@127.0.0.1:3306/
/usr/lib/mysqlsh/plugins/gui_plugin/core/dbms/DbMySQLSession.py:360: SyntaxWarning: 'return' in a 'finally' block
  return {

sql> \quit
Bye!
dvaneeden@dve-carbon:~$ rpm -qf /usr/lib/mysqlsh/plugins/gui_plugin/core/dbms/DbMySQLSession.py
mysql-shell-9.6.0-1.fc43.x86_64

How to repeat:
See description
[21 Jan 11:52] Daniël van Eeden
https://github.com/mysql/mysql-shell-plugins/blame/01fd61aed3cdc9becdfd056cabd0579655c50ef...

https://peps.python.org/pep-0765/
[21 Jan 12:07] Daniël van Eeden
Looks like MySQL Shell 9.5 used Python 3.13 and MySQL Shell 9.6 upgraded the Python 3.14. So that's why this SyntaxWarning suddendly appears for old code.

Weirdly enough this wasn't in the release notes.
[21 Jan 14:55] Alfredo Kojima
Hi Daniel, do you have custom plugins installed? Could you start the shell with `--verbose=2 --log-level=8` to get more details?
[21 Jan 16:21] Daniël van Eeden
------------------------------------------------------------------------------
$ mysqlsh --verbose=2 --log-level=8 mysql://root@127.0.0.1:3306/
verbose: 2026-01-21T17:12:07Z: Loading startup files...
verbose: 2026-01-21T17:12:07Z: Searching for plugins at '/usr/lib/mysqlsh/plugins'
verbose: 2026-01-21T17:12:07Z: Loading plugins...
/usr/lib/mysqlsh/plugins/gui_plugin/core/dbms/DbMySQLSession.py:360: SyntaxWarning: 'return' in a 'finally' block
  return {
verbose: 2026-01-21T17:12:11Z: Using color mode 2
verbose: 2026-01-21T17:12:11Z: Connecting to MySQL at: mysql://root@127.0.0.1:3306
verbose: 2026-01-21T17:12:11Z: main: tid=0: CONNECTED: 127.0.0.1:3306
verbose: 2026-01-21T17:12:11Z: Using prompt theme file /home/dvaneeden/.mysqlsh/prompt.json

sql> 
------------------------------------------------------------------------------

And to verify that it is not my installation, I tried with a container:
------------------------------------------------------------------------------
podman run --net=host --rm -it fedora:43
rpm -i https://dev.mysql.com/get/mysql84-community-release-fc43-1.noarch.rpm
dnf install --enablerepo=mysql-tools-innovation-community -y mysql-shell
mysqlsh --verbose=2 --log-level=8 mysql://root@127.0.0.1:3306/
------------------------------------------------------------------------------

This gave me this output:
------------------------------------------------------------------------------
# mysqlsh --verbose=2 --log-level=8 mysql://root@127.0.0.1:3306/
Cannot set LC_ALL to locale en_US.UTF-8: No such file or directory
verbose: 2026-01-21T16:18:02Z: Loading startup files...
verbose: 2026-01-21T16:18:02Z: Searching for plugins at '/usr/lib/mysqlsh/plugins'
verbose: 2026-01-21T16:18:02Z: Loading plugins...
/usr/lib/mysqlsh/plugins/gui_plugin/core/dbms/DbMySQLSession.py:360: SyntaxWarning: 'return' in a 'finally' block
  return {
verbose: 2026-01-21T16:18:07Z: Using color mode 2
Please provide the password for 'root@127.0.0.1:3306': 
verbose: 2026-01-21T16:18:10Z: Connecting to MySQL at: mysql://root@127.0.0.1:3306
verbose: 2026-01-21T16:18:10Z: main: tid=0: CONNECTED: 127.0.0.1:3306
Save password for 'root@127.0.0.1:3306'? [Y]es/[N]o/Ne[v]er (default No): 
MySQL Shell 9.6.0

Copyright (c) 2016, 2026, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a Classic session to 'root@127.0.0.1:3306'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 10
Server version: 9.5.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
verbose: 2026-01-21T16:18:12Z: Using prompt theme file /usr/share/mysqlsh/prompt/prompt_256.json
 MySQL  127.0.0.1:3306 ssl  SQL > \status
MySQL Shell version 9.6.0

Connection Id:                10
Current schema:               
Current user:                 root@192.168.1.219
SSL:                          Cipher in use: TLS_AES_128_GCM_SHA256 TLSv1.3
Using delimiter:              ;
Server version:               9.5.0 MySQL Community Server - GPL
Protocol version:             Classic 10
Client library:               9.6.0
Connection:                   127.0.0.1 via TCP/IP
TCP port:                     3306
Server characterset:          utf8mb4
Schema characterset:          utf8mb4
Client characterset:          utf8mb4
Conn. characterset:           utf8mb4
Result characterset:          utf8mb4
Compression:                  Disabled
Uptime:                       6 min 30.0000 sec

Threads: 2  Questions: 41  Slow queries: 0  Opens: 172  Flush tables: 3  Open tables: 91  Queries per second avg: 0.105
 MySQL  127.0.0.1:3306 ssl  SQL > \quit
Bye!
------------------------------------------------------------------------------

So you should be able to reproduce this with a `fedora:43` container (or VM)
[21 Jan 16:32] Daniël van Eeden
I tried the same with a Fedora 42 container:
------------------------
podman run --net=host --rm -it fedora:42
rpm -i https://dev.mysql.com/get/mysql84-community-release-fc42-3.noarch.rpm
dnf install --enablerepo=mysql-tools-innovation-community -y mysql-shell
------------------------

This does *not* show the SyntaxWarning.

Looking at the files in the package it looks like mysql-shell on Fedora 42 is still using Python 3.13, which doesn't give this warning.

On Fedora 42:
------------------------
# rpm -ql mysql-shell | grep -E '/python[0-9\.]+$'
/usr/lib/mysqlsh/lib/python3.13
------------------------
[21 Jan 16:42] Daniël van Eeden
On Fedora 42:
-----------------------
 MySQL  Py > def f():
          ->     try:
          ->         ...
          ->     finally:
          ->         return 42
          -> 
 MySQL  Py > f()
42
 MySQL  Py > import platform
 MySQL  Py > platform.python_version()
3.13.11
-----------------------

On Fedora 43 (ignore the prompt):
-----------------------
py> def f():
   ->     try:
   ->         ...
   ->     finally:
   ->         return 42
   -> 
<string>:5: SyntaxWarning: 'return' in a 'finally' block

py> f()
42
py> import platform
py> platform.python_version()
3.14.2
-----------------------

Both in Python mode.