Describe the bug
The AI assistant "Generate SQL" feature fails on every request with a Python
TypeError. pgAdmin catches the exception and returns the message
"Failed to generate SQL: unsupported operand type(s) for |: 'type' and 'NoneType'"
to the browser, and no SQL is generated.
Root cause: PEP 604 union syntax (X | None) is used in
web/pgadmin/llm/tools/database.py. That syntax is only valid as a runtime
expression on Python 3.10+. On Python 3.9 the annotations raise TypeError when
they are evaluated. pgAdmin 9.15 still officially supports Python 3.9 (the PyPI
classifiers list 3.9 through 3.13, and the RHEL 9 RPM ships a 3.9 venv), so this
is a regression in the new LLM tools code.
To Reproduce
Steps to reproduce the behavior:
- Install pgAdmin 9.15 on a Python 3.9 runtime (e.g. the RHEL 9 RPM, whose venv
is built on the system Python 3.9).
- Configure an LLM provider under Preferences > AI (e.g. Anthropic, with API URL
and API key file set).
- Open the Query Tool against any connected database.
- Ask the AI assistant to generate SQL from a natural language prompt.
- See the error.
Expected behavior
The AI assistant generates SQL without error on Python 3.9, consistent with 3.9
being a supported runtime.
Error message
Failed to generate SQL: unsupported operand type(s) for |: 'type' and 'NoneType'
(The full traceback is swallowed by the request handler. The TypeError originates
from the X | None annotations in web/pgadmin/llm/tools/database.py being
evaluated under Python 3.9.)
Screenshots
N/A
Desktop (please complete the following information):
- OS: Red Hat Enterprise Linux 9
- pgAdmin version: 9.15
- Mode: Server
- Package type: RPM (pgadmin4-server 9.15-1.el9, running under
Apache 2.4.62 / mod_wsgi 4.7.1 / Python 3.9.25)
Additional context
Suggested fix: replace the PEP 604 union syntax (X | None) in
web/pgadmin/llm/tools/database.py with typing.Optional[X], or add
"from future import annotations" at the top of the module so the annotations
are stored as strings and not evaluated at runtime. Either restores Python 3.9
compatibility. A repo-wide grep for "| None" in the llm/ tree is worth doing in
case other tool modules have the same issue.
I can submit the PR for it. I just don't have branch permissions. I found no other occurences of the issue in the rest of the codebase.
Describe the bug
The AI assistant "Generate SQL" feature fails on every request with a Python
TypeError. pgAdmin catches the exception and returns the message
"Failed to generate SQL: unsupported operand type(s) for |: 'type' and 'NoneType'"
to the browser, and no SQL is generated.
Root cause: PEP 604 union syntax (X | None) is used in
web/pgadmin/llm/tools/database.py. That syntax is only valid as a runtime
expression on Python 3.10+. On Python 3.9 the annotations raise TypeError when
they are evaluated. pgAdmin 9.15 still officially supports Python 3.9 (the PyPI
classifiers list 3.9 through 3.13, and the RHEL 9 RPM ships a 3.9 venv), so this
is a regression in the new LLM tools code.
To Reproduce
Steps to reproduce the behavior:
is built on the system Python 3.9).
and API key file set).
Expected behavior
The AI assistant generates SQL without error on Python 3.9, consistent with 3.9
being a supported runtime.
Error message
Failed to generate SQL: unsupported operand type(s) for |: 'type' and 'NoneType'
(The full traceback is swallowed by the request handler. The TypeError originates
from the X | None annotations in web/pgadmin/llm/tools/database.py being
evaluated under Python 3.9.)
Screenshots
N/A
Desktop (please complete the following information):
Apache 2.4.62 / mod_wsgi 4.7.1 / Python 3.9.25)
Additional context
Suggested fix: replace the PEP 604 union syntax (X | None) in
web/pgadmin/llm/tools/database.py with typing.Optional[X], or add
"from future import annotations" at the top of the module so the annotations
are stored as strings and not evaluated at runtime. Either restores Python 3.9
compatibility. A repo-wide grep for "| None" in the llm/ tree is worth doing in
case other tool modules have the same issue.
I can submit the PR for it. I just don't have branch permissions. I found no other occurences of the issue in the rest of the codebase.