Skip to content

Commit 3ca32d5

Browse files
jopemachineclaude
andcommitted
refactor(BA-5837): align cache-aware admin_repo with Updater/Purger pattern
The Valkey cache wrapper added in this PR re-introduced the `(key, spec)` and `(key)` signatures on `db_source.update` / `db_source.purge`. Switch the cache-aware admin_repository over to the Updater/Purger pattern from BA-5827 while keeping the merged- view cache-invalidation hooks intact. Also rename the residual `extra_config` / `extraConfig` references in the GQL types and schema dump to `config` for consistency with the column rename. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1842b40 commit 3ca32d5

5 files changed

Lines changed: 30 additions & 96 deletions

File tree

docs/manager/graphql-reference/supergraph.graphql

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11525,52 +11525,6 @@ input MyAppConfigFragmentItemInput
1152511525
config: JSON!
1152611526
}
1152711527

11528-
"""
11529-
Added in UNRELEASED. Self-service bulk create — scope is `USER` / `current_user`.
11530-
"""
11531-
input MyBulkCreateAppConfigFragmentInput
11532-
@join__type(graph: STRAWBERRY)
11533-
{
11534-
"""USER-scope rows to create."""
11535-
items: [MyAppConfigFragmentItemInput!]!
11536-
}
11537-
11538-
"""
11539-
Added in UNRELEASED. Payload for `bulkCreateMyAppConfigFragments` (recomputed views).
11540-
"""
11541-
type MyBulkCreateAppConfigFragmentsPayload
11542-
@join__type(graph: STRAWBERRY)
11543-
{
11544-
"""Recomputed merged AppConfig views for each created USER fragment."""
11545-
created: [AppConfig!]!
11546-
11547-
"""Per-item failures."""
11548-
failed: [AppConfigFragmentBulkError!]!
11549-
}
11550-
11551-
"""
11552-
Added in UNRELEASED. Self-service bulk update — scope is `USER` / `current_user`.
11553-
"""
11554-
input MyBulkUpdateAppConfigFragmentInput
11555-
@join__type(graph: STRAWBERRY)
11556-
{
11557-
"""USER-scope rows to update."""
11558-
items: [MyAppConfigFragmentItemInput!]!
11559-
}
11560-
11561-
"""
11562-
Added in UNRELEASED. Payload for `bulkUpdateMyAppConfigFragments` (recomputed views).
11563-
"""
11564-
type MyBulkUpdateAppConfigFragmentsPayload
11565-
@join__type(graph: STRAWBERRY)
11566-
{
11567-
"""Recomputed merged AppConfig views for each updated USER fragment."""
11568-
updated: [AppConfig!]!
11569-
11570-
"""Per-item failures."""
11571-
failed: [AppConfigFragmentBulkError!]!
11572-
}
11573-
1157411528
"""
1157511529
Added in 26.4.2. Query result returning the current client's IP address.
1157611530
"""

docs/manager/graphql-reference/v2-schema.graphql

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7415,44 +7415,6 @@ input MyAppConfigFragmentItemInput {
74157415
config: JSON!
74167416
}
74177417

7418-
"""
7419-
Added in UNRELEASED. Self-service bulk create — scope is `USER` / `current_user`.
7420-
"""
7421-
input MyBulkCreateAppConfigFragmentInput {
7422-
"""USER-scope rows to create."""
7423-
items: [MyAppConfigFragmentItemInput!]!
7424-
}
7425-
7426-
"""
7427-
Added in UNRELEASED. Payload for `bulkCreateMyAppConfigFragments` (recomputed views).
7428-
"""
7429-
type MyBulkCreateAppConfigFragmentsPayload {
7430-
"""Recomputed merged AppConfig views for each created USER fragment."""
7431-
created: [AppConfig!]!
7432-
7433-
"""Per-item failures."""
7434-
failed: [AppConfigFragmentBulkError!]!
7435-
}
7436-
7437-
"""
7438-
Added in UNRELEASED. Self-service bulk update — scope is `USER` / `current_user`.
7439-
"""
7440-
input MyBulkUpdateAppConfigFragmentInput {
7441-
"""USER-scope rows to update."""
7442-
items: [MyAppConfigFragmentItemInput!]!
7443-
}
7444-
7445-
"""
7446-
Added in UNRELEASED. Payload for `bulkUpdateMyAppConfigFragments` (recomputed views).
7447-
"""
7448-
type MyBulkUpdateAppConfigFragmentsPayload {
7449-
"""Recomputed merged AppConfig views for each updated USER fragment."""
7450-
updated: [AppConfig!]!
7451-
7452-
"""Per-item failures."""
7453-
failed: [AppConfigFragmentBulkError!]!
7454-
}
7455-
74567418
"""
74577419
Added in 26.4.2. Query result returning the current client's IP address.
74587420
"""

src/ai/backend/manager/api/gql/app_config_fragment/types/bulk_inputs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
)
4747
class AdminAppConfigFragmentItemInputGQL(PydanticInputMixin[AdminItemInputDTO]):
4848
key: AppConfigFragmentKeyInputGQL = gql_field(description="Natural-key identifier.")
49-
extra_config: dict[str, Any] = gql_field(description="Raw configuration payload.")
49+
config: dict[str, Any] = gql_field(description="Raw configuration payload.")
5050

5151

5252
@gql_pydantic_input(
@@ -91,7 +91,7 @@ class AdminBulkPurgeAppConfigFragmentInputGQL(PydanticInputMixin[AdminBulkPurgeI
9191
)
9292
class MyAppConfigFragmentItemInputGQL(PydanticInputMixin[MyItemInputDTO]):
9393
name: str = gql_field(description="Policy name.")
94-
extra_config: dict[str, Any] = gql_field(description="Raw configuration payload.")
94+
config: dict[str, Any] = gql_field(description="Raw configuration payload.")
9595

9696

9797
@gql_pydantic_input(

src/ai/backend/manager/api/gql/app_config_fragment/types/node.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class AppConfigFragmentGQL(PydanticOutputMixin[AppConfigFragmentNode]):
4141
scope_type: AppConfigScopeType = gql_field(description="Scope type.")
4242
scope_id: str = gql_field(description="Scope id.")
4343
name: str = gql_field(description="Policy name (FK to app_config_policies).")
44-
extra_config: dict[str, Any] | None = gql_field(
45-
description="Raw configuration payload, or null."
46-
)
44+
config: dict[str, Any] | None = gql_field(description="Raw configuration payload, or null.")
4745
created_at: datetime = gql_field(description="Creation timestamp.")
4846
updated_at: datetime | None = gql_field(description="Last update timestamp.")

src/ai/backend/manager/repositories/app_config_fragment/admin_repository.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,39 @@ async def update(
116116
key: AppConfigFragmentKey,
117117
config: Mapping[str, Any],
118118
) -> AppConfigFragmentData:
119-
"""Update a fragment by natural key. Raises
120-
``AppConfigFragmentNotFound`` when missing."""
121-
spec = AppConfigFragmentUpdaterSpec(extra_config=extra_config)
122-
result = await self._db_source.update(key, spec)
119+
"""Update a fragment by natural key. Resolves the natural key
120+
to the row's UUID, builds an ``Updater``, and delegates to the
121+
DB source. Raises :class:`AppConfigFragmentNotFound` when the
122+
row is missing (or vanishes between resolve and write)."""
123+
pk_value = await self._db_source.resolve_pk_by_key(key)
124+
if pk_value is None:
125+
raise _missing(key)
126+
updater: Updater[AppConfigFragmentRow] = Updater(
127+
spec=AppConfigFragmentUpdaterSpec(config=config),
128+
pk_value=pk_value,
129+
)
130+
result = await self._db_source.update(updater)
131+
if result is None:
132+
raise _missing(key)
123133
await self._invalidate(key)
124134
return result
125135

126136
@app_config_fragment_admin_repository_resilience.apply()
127137
async def purge(self, key: AppConfigFragmentKey) -> bool:
128-
result = await self._db_source.purge(key)
129-
if result:
138+
"""Delete a fragment by natural key. Resolves the natural key,
139+
builds a ``Purger``, delegates to the DB source, and (on a
140+
real removal) invalidates the merged-view cache."""
141+
pk_value = await self._db_source.resolve_pk_by_key(key)
142+
if pk_value is None:
143+
return False
144+
purger: Purger[AppConfigFragmentRow] = Purger(
145+
row_class=AppConfigFragmentRow,
146+
pk_value=pk_value,
147+
)
148+
removed = await self._db_source.purge(purger)
149+
if removed:
130150
await self._invalidate(key)
131-
return result
151+
return removed
132152

133153
async def _invalidate(self, key: AppConfigFragmentKey) -> None:
134154
if self._cache_source is None:

0 commit comments

Comments
 (0)