Skip to content

Commit 55ee94e

Browse files
committed
feat: update column definitions for owner and last_updated in migrations and models
1 parent 1e19e18 commit 55ee94e

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/a2a/migrations/versions/6419d2d130f6_add_columns_owner_last_updated.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def _get_inspector() -> sa.engine.reflection.Inspector:
3535
def _add_column(
3636
table: str,
3737
column_name: str,
38+
nullable: bool,
3839
type_: sa.types.TypeEngine,
3940
value: str | None = None,
4041
) -> None:
@@ -44,7 +45,7 @@ def _add_column(
4445
sa.Column(
4546
column_name,
4647
type_,
47-
nullable=False,
48+
nullable=nullable,
4849
server_default=value,
4950
),
5051
)
@@ -112,8 +113,8 @@ def upgrade() -> None:
112113
)
113114

114115
if _table_exists(tasks_table):
115-
_add_column(tasks_table, 'owner', sa.String(128), owner)
116-
_add_column(tasks_table, 'last_updated', sa.DateTime(timezone=True))
116+
_add_column(tasks_table, 'owner', False, sa.String(128), owner)
117+
_add_column(tasks_table, 'last_updated', True, sa.DateTime())
117118
_add_index(
118119
tasks_table,
119120
f'idx_{tasks_table}_owner_last_updated',
@@ -126,7 +127,11 @@ def upgrade() -> None:
126127

127128
if _table_exists(push_notification_configs_table):
128129
_add_column(
129-
push_notification_configs_table, 'owner', sa.String(128), owner
130+
push_notification_configs_table,
131+
'owner',
132+
False,
133+
sa.String(128),
134+
owner,
130135
)
131136
else:
132137
logging.warning(

src/a2a/server/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class TaskMixin:
151151
)
152152
owner: Mapped[str] = mapped_column(String(128), nullable=False)
153153
last_updated: Mapped[datetime | None] = mapped_column(
154-
DateTime(timezone=True), nullable=True
154+
DateTime, nullable=True
155155
)
156156

157157
# Properly typed Pydantic fields with automatic serialization

src/a2a/server/tasks/database_task_store.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from datetime import datetime, timezone
34
from typing import Any, cast
45

56

@@ -234,9 +235,13 @@ async def list(
234235
count_stmt = select(func.count()).select_from(base_stmt.alias())
235236
total_count = (await session.execute(count_stmt)).scalar_one()
236237

237-
# Use nulls_last() to ensure NULL timestamps sort last in descending order
238+
# Use coalesce to treat NULL timestamps as datetime.min,
239+
# which sort last in descending order
238240
stmt = base_stmt.order_by(
239-
timestamp_col.desc().nulls_last(),
241+
func.coalesce(
242+
timestamp_col,
243+
datetime.min.replace(tzinfo=timezone.utc),
244+
).desc(),
240245
self.task_model.id.desc(),
241246
)
242247

0 commit comments

Comments
 (0)