openai / openai/openai-agents-python
SQLAlchemySession(create_tables=True) cannot create tables on MySQL due to unbounded String columns
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 29.6k
- Forks
- 4.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 123
Description
The session guide lists MySQL as a supported database, and the API reference includes mysql+aiomysql:// and documents create_tables=True for development/testing. However, automatic table creation fails against a fresh MySQL database.
Reproduction
Reproduced with MySQL Community Server 8.0.46, Python 3.12.3 on Linux, openai-agents 0.22.0, SQLAlchemy 2.0.52, and aiomysql 0.3.2. The same failure occurs on main at 89c02c828ee8510fe9a84ee6675608193aa13b02.
Install the dependencies, then set MYSQL_URL to a mysql+aiomysql:// connection URL for an empty test database with permission to create tables. No model call or OpenAI API key is needed.
pip install 'openai-agents[sqlalchemy]==0.22.0' 'SQLAlchemy==2.0.52' 'aiomysql==0.3.2' cryptography
import asyncio
import os
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
from agents.extensions.memory import SQLAlchemySession
async def main():
engine = create_async_engine(os.environ["MYSQL_URL"])
try:
async with engine.connect() as conn:
print("MySQL:", await conn.scalar(text("SELECT VERSION()")))
session = SQLAlchemySession(
"mysql-create-tables",
engine=engine,
create_tables=True,
)
await session.add_items([{"role": "user", "content": "hello"}])
finally:
await engine.dispose()
asyncio.run(main())
Actual result
The connection succeeds and reports MySQL 8.0.46. On the first add_items() call, automatic schema initialization fails with:
sqlalchemy.exc.CompileError: (in table 'agent_sessions', column 'session_id'): VARCHAR requires a length on dialect mysql
This happens while SQLAlchemy compiles the first CREATE TABLE, before any CREATE statement reaches MySQL. No tables are created.
Both session_id columns in the current implementation use String without a length.
Expected behavior / scope clarification
Is SQLAlchemySession(create_tables=True) intended to support MySQL?
If so, I would expect the example above to create the required tables and store the message, and I'd be happy to submit a focused fix with MySQL regression coverage.
If automatic schema creation is intentionally unsupported on MySQL, I can instead submit a documentation clarification.
One possible implementation direction is a MySQL-specific bounded VARCHAR via with_variant(), which would preserve the existing PostgreSQL/SQLite types. I have not chosen a length here because doing so would introduce a MySQL-specific maximum session ID length that should be agreed first.
This report is limited to automatic table creation on a fresh database; it does not assess create_tables=False with a manually provisioned schema.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/agents/extensions/memory/sqlalchemy_session.py, where both session_id columns use unbounded String, and reproduce the failure with the provided MySQL setup and script. Review SQLAlchemy with_variant() and the existing PostgreSQL/SQLite types before choosing the bounded MySQL type. Done means create_tables=True creates the required tables and stores the message, with MySQL regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, python, sqlalchemy
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100