[Bug] Management utilities print SyntaxWarning: invalid escape sequence on Python 3.12+ (e.g. Rocky Linux 10)
まだ誰も着手していません。
評価
調査の方向性
gpMgmt/ 配下にある一覧の16個のファイル、特に gpMgmt/bin/gppylib/util/ssh_utils.py と gpMgmt/bin/lib/pexpect/pxssh.py から始め、次に Python 3.12 の py_compile 再現コマンドを実行します。gpMgmt/ 配下で報告された41個のリテラルを値を維持したまま更新し、SyntaxWarning をエラーとして扱ったコンパイル、および gpsync または gpssh --help で警告が発生しないことを確認します。
索引モデルが issue の本文から書いたものです。
説明
Apache Cloudberry version
main (89baa48a4f4) — also present in 2.x releases.
What happened
On a Rocky Linux 10 cluster (Python 3.12), every invocation of gpsync /
gpssh / gpssh-exkeys prints SyntaxWarning messages to stderr before it
does any work. It surfaced while installing the Cloudberry backup utilities,
whose make install calls gpsync to distribute binaries to the segments:
$ make install
cp /home/gpadmin/go/bin/gpbackup ... /usr/local/cloudberry-db/bin
/usr/local/cloudberry-db/lib/python/gppylib/util/ssh_utils.py:268: SyntaxWarning: invalid escape sequence '\ '
'''Escape occurrences of \ and $ as needed and package the line as an "eval" shell command'''
/usr/local/cloudberry-db/bin/lib/pexpect/pxssh.py:105: SyntaxWarning: invalid escape sequence '\['
self.UNIQUE_PROMPT = "\[PEXPECT\][\$\#] "
/usr/local/cloudberry-db/bin/lib/pexpect/pxssh.py:109: SyntaxWarning: invalid escape sequence '\$'
self.PROMPT_SET_SH = "PS1='[PEXPECT]\$ '"
/usr/local/cloudberry-db/bin/lib/pexpect/pxssh.py:110: SyntaxWarning: invalid escape sequence '\$'
self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\$ '"
Successfully copied gpbackup_helper and gpbackup_s3_plugin to /usr/local/cloudberry-db on all segments
The operation itself succeeds — this is cosmetic — but it makes utility output
noisy and looks like a failure to anyone reading a deployment log.
Why it appears now: string literals such as "\[" or "\$" contain escape
sequences Python does not recognise. Until 3.11 that was a DeprecationWarning,
hidden by default; Python 3.12 promoted it to a SyntaxWarning, which is
printed (What's New in 3.12).
So the same code is quiet on Rocky 8/9 (Python 3.6/3.9) and noisy on Rocky 10,
Fedora 40+, and Ubuntu 24.10+. The Python docs also state these sequences
will become a SyntaxError in a future release, so this is not purely
cosmetic in the long run.
Note the warnings can repeat on every run: if $GPHOME is root-owned and the
utility runs as gpadmin, CPython cannot write __pycache__, so the modules
are recompiled — and re-warn — each time.
What you think should happen instead
gpsync/gpssh should produce no Python warnings. The literals in question are
regexes and shell snippets that were meant to be raw strings; they should be
written as such (r"\[PEXPECT\]..."), which leaves their value unchanged.
Compiling everything under gpMgmt/ shows the problem is broader than the four
warnings above — 41 literals in 16 files:
| File | Lines |
|---|---|
gpMgmt/bin/gpload.py |
720, 2530, 2675, 2689 |
gpMgmt/bin/gpload_test/gpload/TEST.py |
322 (×2), 329, 331, 333, 335, 353, 355, 410 |
gpMgmt/bin/gppylib/programs/test/unit/test_cluster_clsrecoversegment_triples.py |
297, 304, 332 |
gpMgmt/bin/gppylib/test/unit/test_unit_database_segment_guc.py |
26 |
gpMgmt/bin/gppylib/test/unit/test_unit_file_segment_guc.py |
31 |
gpMgmt/bin/gppylib/test/unit/test_unit_gppkg.py |
72 |
gpMgmt/bin/gppylib/test/unit/test_unit_gpsegrecovery.py |
304, 333 |
gpMgmt/bin/gppylib/test/unit/test_unit_gpsegsetuprecovery.py |
262, 287 |
gpMgmt/bin/gppylib/test/unit/test_unit_package.py |
122 |
gpMgmt/bin/gppylib/util/ssh_utils.py |
268 |
gpMgmt/bin/lib/pexpect/pxssh.py |
105, 109, 110 |
gpMgmt/sbin/seg_update_pg_hba.py |
41 |
gpMgmt/test/behave/mgmt_utils/steps/gpstate_utils.py |
79 |
gpMgmt/test/behave/mgmt_utils/steps/mgmt_utils.py |
683, 908, 2007, 2223, 3346, 3351, 3849, 3980 |
gpMgmt/test/behave/mgmt_utils/steps/replication_slots_utils.py |
27, 90 |
gpMgmt/test/behave_utils/utils.py |
682 |
A further 67 literals in 11 files under src/ and contrib/ have the same
problem (src/backend/gporca/scripts/, contrib/try_convert/scripts/). Those
are developer scripts rather than shipped utilities, so they are lower priority.
Two side findings while auditing:
gpMgmt/bin/lib/pexpectis a vendored copy of pexpect 3.3 (2013).
Upstream pexpect made these literals raw years ago; refreshing the vendored
copy — or dropping it in favour of the packagedpexpect— would be worth
considering separately.gpMgmt/test/behave/mgmt_utils/steps/replication_slots_utils.py:31reads
export WITH_MIRRORS={with_mirrors} && \A, in the middle of a run of shell
line continuations. The strayAlooks like a keystroke slip: the shell
receives&& A ./demo_cluster.sh -d && ...and tries to run a command named
A. Pre-existing, unrelated to the encoding of the escape, and probably
deserves its own fix.
How to reproduce
On any host with Python 3.12 or newer (Rocky Linux 10, Fedora 40+,
Ubuntu 24.10+):
$ gpsync --help # or: gpssh --help
Or without a cluster, straight from a source checkout:
$ python3 --version
Python 3.12.4
$ python3 -W error::SyntaxWarning -m py_compile \
gpMgmt/bin/gppylib/util/ssh_utils.py gpMgmt/bin/lib/pexpect/pxssh.py
To enumerate every occurrence in the tree:
$ python3 - <<'PY'
import pathlib, warnings
for p in sorted(pathlib.Path('gpMgmt').rglob('*.py')):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
try:
compile(p.read_text(encoding='utf-8', errors='replace'), str(p), 'exec')
except SyntaxError:
continue
for i in w:
if issubclass(i.category, SyntaxWarning):
print(f'{p}:{i.lineno}: {i.message}')
PY
Operating System
Rocky Linux 10 (Python 3.12); reproduced on macOS with Python 3.12.4.
Anything else
Happens every time on Python 3.12+, never on Python ≤ 3.11.
Workaround for operators until this is fixed:
$ PYTHONWARNINGS=ignore::SyntaxWarning make install
I am preparing a PR that fixes the 41 literals under gpMgmt/, with the
src/+contrib/ remainder as a follow-up.
Are you willing to submit PR?
- Yes, I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct.
- 主要言語
- C
- スター
- 1.4k
- フォーク
- 248
- 平均マージ
- 4日 10時間
- マージ済み PR(30日)
- 40
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/cloudberry のほかの issue
-
type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
apache/cloudberry#1885 · リアクション 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
apache/cloudberry#1825 ·
-
type: Bug
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
apache/cloudberry#2048 · リアクション 1 件 ·
-
type: Bug
難易度 4/5 3〜5日 初心者へのやさしさ 40/100
apache/cloudberry#2047 ·
-
type: Bug
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
apache/cloudberry#2046 · コメント 1 件 ·
apache/cloudberry の issue をすべて見る
似ている issue
-
task
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
vsanthanam/JBird#429 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
bug documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
es-ude/OnDeviceTraining#459 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
bilelmoussaoui/gobject-linter#199 · コメント 1 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
bradcypert/plum#53 ·