-
Notifications
You must be signed in to change notification settings - Fork 12
fix(api): implement idempotent repository creation endpoint #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Previously, POSTing the same repository URI twice would return a 500 error due to an unhandled IntegrityError from the database UNIQUE constraint. This change implements proper idempotent behavior where: - First POST: Creates repository → Returns 201 Created - Subsequent POSTs: Triggers re-indexing → Returns 200 OK - No duplicate data is created in the database Changes: - Update create_git_repository() to check for existing repos by sanitized URI using QueryBuilder pattern - Return tuple (GitRepo, bool) indicating if repo was newly created - Modify API endpoint to set appropriate status code (201 vs 200) - Add regression tests for deletion and indexing idempotency The implementation follows RESTful idempotency principles where multiple identical requests produce the same result. Tests added: - test_deletion_smoke.py: Verifies repository deletion cleans up all associated data (found bug: embeddings table not fully cleaned) - test_indexing_idempotency.py: Verifies no duplicate data created when re-indexing same repository
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.
Summary
Implements proper idempotent behavior for the
POST /api/v1/repositoriesendpoint. Previously, attempting to create a repository with a duplicate URI would return a 500 Internal Server Error due to an unhandled databaseIntegrityError. Now the endpoint follows RESTful idempotency principles:201 Created200 OKChanges
Core Implementation
CommitIndexingApplicationService.create_git_repository():QueryBuilder.filter()(GitRepo, bool)where boolean indicates if newly createdPOST /api/v1/repositoriesendpoint:201 Createdfor new,200 OKfor existingTesting
Added two comprehensive regression tests:
test_deletion_smoke.py: Verifies repository deletion properly cleans up all associated dataembeddingstable still has 6 rows after deletion (documented in test)test_indexing_idempotency.py: Verifies no duplicate data when re-indexing same repositoryTest Plan
test_indexing_idempotency.py- passes, verifies idempotent behaviortest_deletion_smoke.py- passes (documents embeddings bug)Related Issues
Fixes the bug where duplicate repository creation attempts returned 500 errors instead of handling gracefully.
Notes
The deletion test identified an existing bug where the
embeddingstable is not fully cleaned up during repository deletion. This is documented in the test but not fixed in this PR to keep the scope focused on the idempotency fix.