Skip to content

Commit bae12a7

Browse files
vpeterssonclaude
andcommitted
fix(server): info toast on bulk_update with no matching ids
Seventh Copilot pass on #3048: assets_bulk_update returned a silent no-toast 2xx when the posted ids matched no rows (stale selection), so the client's success gate cleared the selection / closed the modal even though nothing applied. Return the same info toast the enable/disable path uses so the selection is kept. Adds a test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a31a264 commit bae12a7

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/anthias_server/app/views.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,15 @@ def assets_bulk_update(request: HttpRequest) -> HttpResponse:
804804
return _asset_table_response(request)
805805
assets = list(Asset.objects.filter(asset_id__in=ids))
806806
if not assets:
807-
return _asset_table_response(request)
807+
# Non-empty ids that match nothing (e.g. a stale selection after
808+
# another operator deleted the rows). Toast so the client's
809+
# success gate keeps the selection / leaves the modal open
810+
# rather than treating a silent no-toast 2xx as success — same
811+
# contract as the enable/disable path.
812+
return _asset_table_response(
813+
request,
814+
toast=('info', 'No matching assets selected'),
815+
)
808816

809817
apply_dates = request.POST.get('apply_dates') == 'true'
810818
apply_duration = request.POST.get('apply_duration') == 'true'

tests/test_template_views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,32 @@ def test_assets_bulk_action_no_matching_ids_keeps_selection(
11911191
assert trigger['toast']['kind'] == 'info'
11921192

11931193

1194+
@pytest.mark.django_db
1195+
def test_assets_bulk_update_unmatched_ids_keeps_selection(
1196+
client: Client, bulk_assets: list[Asset]
1197+
) -> None:
1198+
"""bulk_update with non-empty but unmatched ids returns an info
1199+
toast (not a silent no-toast 2xx) so the client keeps the selection
1200+
and the modal stays open (Copilot review of #3048)."""
1201+
import json as _json
1202+
1203+
with mock.patch(
1204+
'anthias_server.settings.ViewerPublisher.send_to_viewer',
1205+
return_value=None,
1206+
):
1207+
response = client.post(
1208+
reverse('anthias_app:assets_bulk_update'),
1209+
data={
1210+
'ids': 'no-such-id,also-missing',
1211+
'apply_duration': 'true',
1212+
'duration': '42',
1213+
},
1214+
HTTP_HX_REQUEST='true',
1215+
)
1216+
trigger = _json.loads(response['HX-Trigger'])
1217+
assert trigger['toast']['kind'] == 'info'
1218+
1219+
11941220
@pytest.mark.django_db
11951221
def test_assets_bulk_update_dates(
11961222
client: Client, bulk_assets: list[Asset]

0 commit comments

Comments
 (0)