Repository navigation
fix(v6.51.3): AI providers can be deleted after they have been used (ADR-255) - #309
Merged
Merged
Conversation
…ADR-255) Deleting a provider referenced by ai_conversations or ai_usage_log hit a foreign-key violation and returned an unhandled 500 (shown in the browser as a CORS error). delete_provider now clears provider_id on those rows before deleting, keeping conversation history and usage logs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On UAT, deleting any non-default AI provider from Admin → Settings → AI showed "Delete failed". The browser console reported a CORS error, but the Render logs show the real cause:
ai_conversations.provider_idandai_usage_log.provider_idreferenceai_providers(id)with noON DELETEaction, so a provider that had ever answered a question couldn't be deleted. The endpoint returned an unhandled 500, and because that error skips the CORS middleware, the browser reported it as a CORS error.Fix
service.delete_providersetsprovider_id = NULLon the referencingai_conversationsandai_usage_logrows, then deletes the provider, all in one commit. History is kept, and each row still records its model name. The default provider still can't be deleted, as before. No schema change; API, MCP and CLI are unchanged, so surface parity is unaffected.Docs
docs/adrs/ADR-255-Delete-Used-AI-Provider.mddocs/adrs/specs/SPEC-255-A-Delete-Used-AI-Provider.mdTests
test_delete_provider_that_has_been_used(withPRAGMA foreign_keys=ON). Written first, it failed with the same FKIntegrityErroras production, and it passes with the fix.backend/tests/test_ai: 232 passedscripts/check_surface_parity.py: passes🤖 Generated with Claude Code
https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9