Repository navigation
Commit 4e133b7
fix(server): create the cluster tables lazily in VersionedDatabaseTaskStore get and delete (#1357)
# Description
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make
sure it goes smoothly:
- [x] Follow the [`CONTRIBUTING`
Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md).
- [x] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- Important Prefixes for
[release-please](https://github.com/googleapis/release-please):
- `fix:` which represents bug fixes, and correlates to a
[SemVer](https://semver.org/) patch.
- `feat:` represents a new feature, and correlates to a SemVer minor.
- `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking
change (indicated by the `!`) and will result in a SemVer major.
- [x] Ensure the tests and linter pass (Run `bash scripts/format.sh`
from the repository root to format)
- [x] Appropriate docs were updated (if necessary)
Fixes #1356 🦕
## Problem
`VersionedDatabaseTaskStore` creates its tables lazily, like
`DatabaseTaskStore`, but only `save()` creates the cluster tables.
`get()` and `delete()` initialize the underlying `DatabaseTaskStore`
only, so when the store is used without calling `initialize()` and the
first operation is a `get()` or a `delete()`, the query on
`task_versions` fails:
```python
store = VersionedDatabaseTaskStore(engine=create_async_engine('sqlite+aiosqlite:///:memory:'))
await store.get('missing', ServerCallContext())
# sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: task_versions
```
## Fix
`get()` and `delete()` (`src/a2a/server/cluster/database_task_store.py`)
now call `self._ensure_cluster_tables()` after initializing the
underlying store, the same way `save()` does. `delete()` also
initializes the underlying store before creating the cluster tables, so
the tables are created in the same order as in `save()`.
`_ensure_cluster_tables()` returns right away once the tables are ready,
so stores that call `initialize()` are not affected.
## Test
Tests were added to the existing suite at
`tests/server/cluster/test_database_versioned_task_store.py`, using a
new `uninitialized_store` fixture that builds the store on an empty
database with `create_table=True` and without calling `initialize()`:
- `test_get_without_initialize_creates_tables`: `get()` of a missing
task returns `None`.
- `test_delete_without_initialize_creates_tables`: `delete()` of a
missing task does not fail, and a later `get()` returns `None`.
Both tests fail on `main` with `no such table: task_versions` and pass
with the fix. No existing test was modified or removed. Happy to adapt
the test approach based on maintainer feedback.
Co-authored-by: mykytanetipa <mykytanetipa@google.com>1 parent babc3f5 commit 4e133b7
2 files changed
Lines changed: 36 additions & 0 deletions
File tree
- src/a2a/server/cluster
- tests/server/cluster
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
| |||
355 | 356 | | |
356 | 357 | | |
357 | 358 | | |
| 359 | + | |
| 360 | + | |
358 | 361 | | |
359 | 362 | | |
360 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
139 | 157 | | |
140 | 158 | | |
141 | 159 | | |
| |||
654 | 672 | | |
655 | 673 | | |
656 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
657 | 690 | | |
658 | 691 | | |
659 | 692 | | |
| |||
0 commit comments