Skip to content

Commit cc29d1f

Browse files
authored
feat: Database forward compatibility: make owner field optional (#812)
# Description Old version is not able to write in databases which are `1.0` compatible because the new `owner` field is mandatory. This change makes the `owner` field `optional` to maintain forward compatibility. ## Tested ### Before change (owner field mandatory) I created a database with tables `tasks` and `push_notification_configs` using `1.0` spec. I then tested it against `0.3` spec by trying to **write** in it. It failed returning an error: `NOT NULL constraint failed: tasks.owner`. Also, I created a database with `0.3` spec `Task` and `PushNotificationConfigs` entries but then made it `1.0` compatible via migration CLI command `uv run a2a-db`. **Reading** such data using `0.3` spec worked, but **writing** failed for the same reason as before. ### After change (owner field optional) I repeated the testing from before. Now writing in `1.0` compatible databases worked. ## Notes Writing in database which was created using `1.0` spec without running the migration `a2a-db` CLI command, created entries which have `owner=NULL` values, contrary to databases that underwent the migration using `a2a-db` which have `owner` field populated with the default value. In my case with `legacy_v03_no_user_info` since I didn't use the `--add_columns_owner_last_updated-default-owner` flag to pass my own custom default value. ## Contributing Guide - [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 #811 🦕
1 parent b033e23 commit cc29d1f

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/a2a/a2a_db_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_parser() -> argparse.ArgumentParser:
5858
parser.add_argument(
5959
'--add_columns_owner_last_updated-default-owner',
6060
dest='owner',
61-
help="Value for the 'owner' column (used in specific migrations). If not set defaults to 'unknown'",
61+
help="Value for the 'owner' column (used in specific migrations). If not set defaults to 'legacy_v03_no_user_info'",
6262
)
6363
_add_shared_args(parser)
6464

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def upgrade() -> None:
4747
)
4848

4949
if table_exists(tasks_table):
50-
add_column(tasks_table, 'owner', False, sa.String(255), owner)
50+
add_column(tasks_table, 'owner', True, sa.String(255), owner)
5151
add_column(tasks_table, 'last_updated', True, sa.DateTime())
5252
add_index(
5353
tasks_table,
@@ -63,7 +63,7 @@ def upgrade() -> None:
6363
add_column(
6464
push_notification_configs_table,
6565
'owner',
66-
False,
66+
True,
6767
sa.String(255),
6868
owner,
6969
)

src/a2a/server/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TaskMixin:
4444
kind: Mapped[str] = mapped_column(
4545
String(16), nullable=False, default='task'
4646
)
47-
owner: Mapped[str] = mapped_column(String(255), nullable=False)
47+
owner: Mapped[str] = mapped_column(String(255), nullable=True)
4848
last_updated: Mapped[datetime | None] = mapped_column(
4949
DateTime, nullable=True
5050
)
@@ -145,7 +145,7 @@ class PushNotificationConfigMixin:
145145
task_id: Mapped[str] = mapped_column(String(36), primary_key=True)
146146
config_id: Mapped[str] = mapped_column(String(255), primary_key=True)
147147
config_data: Mapped[bytes] = mapped_column(LargeBinary, nullable=False)
148-
owner: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
148+
owner: Mapped[str] = mapped_column(String(255), nullable=True, index=True)
149149
protocol_version: Mapped[str | None] = mapped_column(
150150
String(16), nullable=True
151151
)

0 commit comments

Comments
 (0)