Skip to content

Commit fbf03f3

Browse files
committed
Refactoring and bug fixes
1 parent dccd507 commit fbf03f3

File tree

6 files changed

+41
-59
lines changed

6 files changed

+41
-59
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: |
3636
sudo apt-get update && sudo apt-get install -y postgresql-client
3737
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d a2a_test -f ${{ github.workspace }}/docker/postgres/init.sql
38-
export POSTGRES_TEST_DSN="postgresql://postgres:postgres@localhost:5432/a2a_test"
38+
export POSTGRES_TEST_DSN="postgresql+asyncpg://postgres:postgres@localhost:5432/a2a_test"
3939
4040
- name: Install uv
4141
uses: astral-sh/setup-uv@v6

pyproject.toml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
"grpcio>=1.60",
2121
"grpcio-tools>=1.60",
2222
"grpcio_reflection>=1.7.0",
23-
"protobuf==5.29.5",
23+
"protobuf==5.29.5"
2424
]
2525

2626
classifiers = [
@@ -38,22 +38,16 @@ classifiers = [
3838

3939
[project.optional-dependencies]
4040
postgresql = [
41-
"sqlalchemy>=2.0.0",
42-
"asyncpg>=0.30.0",
41+
"sqlalchemy[asyncio,postgresql-asyncpg]>=2.0.0"
4342
]
4443
mysql = [
45-
"sqlalchemy>=2.0.0",
46-
"aiomysql>=0.2.0",
44+
"sqlalchemy[asyncio,aiomysql]>=2.0.0"
4745
]
4846
sqlite = [
49-
"sqlalchemy>=2.0.0",
50-
"aiosqlite>=0.19.0",
47+
"sqlalchemy[asyncio,aiosqlite]>=2.0.0"
5148
]
5249
sql = [
53-
"sqlalchemy>=2.0.0",
54-
"asyncpg>=0.30.0",
55-
"aiomysql>=0.2.0",
56-
"aiosqlite>=0.19.0",
50+
"sqlalchemy[asyncio,postgresql-asyncpg,aiomysql,aiosqlite]>=2.0.0"
5751
]
5852

5953
[project.urls]
@@ -104,8 +98,7 @@ dev = [
10498
"uv-dynamic-versioning>=0.8.2",
10599
"types-protobuf",
106100
"types-requests",
107-
"pre-commit",
108-
"asyncpg-stubs>=0.30.1",
101+
"pre-commit"
109102
]
110103

111104
[[tool.uv.index]]

src/a2a/server/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ class Base(DeclarativeBase):
109109
class TaskMixin:
110110
"""Mixin providing standard task columns with proper type handling."""
111111

112-
id: Mapped[str] = mapped_column(String, primary_key=True, index=True)
113-
contextId: Mapped[str] = mapped_column(String, nullable=False) # noqa: N815
114-
kind: Mapped[str] = mapped_column(String, nullable=False, default='task')
112+
id: Mapped[str] = mapped_column(String(36), primary_key=True, index=True)
113+
contextId: Mapped[str] = mapped_column(String(36), nullable=False) # noqa: N815
114+
kind: Mapped[str] = mapped_column(
115+
String(16), nullable=False, default='task'
116+
)
115117

116118
# Properly typed Pydantic fields with automatic serialization
117119
status: Mapped[TaskStatus] = mapped_column(PydanticType(TaskStatus))

src/a2a/server/tasks/database_task_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ async def save(self, task: Task) -> None:
124124
.values(**update_data)
125125
)
126126
await session.execute(stmt_update)
127+
logger.debug(f'Task {task.id} updated successfully.')
127128
else:
128129
logger.debug(f'Saving new task {task.id} to the database.')
129130
# Map Pydantic fields to database columns
@@ -139,8 +140,7 @@ async def save(self, task: Task) -> None:
139140
), # Map metadata field to task_metadata column
140141
)
141142
session.add(new_task_model)
142-
# Commit is automatic when using session.begin()
143-
logger.info(f'Task {task.id} saved successfully.')
143+
logger.info(f'Task {task.id} created successfully.')
144144

145145
async def get(self, task_id: str) -> Task | None:
146146
"""Retrieves a task from the database by ID."""

tests/server/tasks/test_database_task_store.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,13 @@ async def db_store_parameterized(
125125
await conn.run_sync(Base.metadata.create_all)
126126

127127
# create_table=False as we've explicitly created tables above.
128-
store = DatabaseTaskStore(db_url, create_table=False)
128+
store = DatabaseTaskStore(engine=engine, create_table=False)
129129
# Initialize the store (connects, etc.). Safe to call even if tables exist.
130130
await store.initialize()
131131

132132
yield store
133133

134134
finally:
135-
# Teardown
136-
if store: # If store was successfully created
137-
await store.close() # Closes the store's own engine
138-
139135
if engine: # If engine was created for setup/teardown
140136
# Drop tables using the fixture's engine
141137
async with engine.begin() as conn:

uv.lock

Lines changed: 26 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)