-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/detect duplicate name in put #22
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
Conversation
WalkthroughAdds specific IntegrityError handling for unique name violations during Category and Subcategory updates, returning HTTP 409 with targeted messages. Aligns PUT behavior with existing POST logic. Updates tests to inline auth header creation and adds new tests asserting duplicate-name update conflicts for categories and subcategories. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant API as Category PUT /categories/{id}
participant DB as Database
C->>API: PUT { name: "NewName", ... }
API->>DB: Update category
DB-->>API: IntegrityError (UniqueViolation on name)
alt Name unique constraint violated
API-->>C: 409 Conflict (Category name already exists)
else Other constraint violations
API-->>C: 409 Conflict (existing linkage constraint handling)
end
sequenceDiagram
autonumber
participant C as Client
participant API as Subcategory PUT /subcategories/{id}
participant DB as Database
C->>API: PUT { name: "NewSubName", ... }
API->>DB: Update subcategory
DB-->>API: IntegrityError (UniqueViolation)
alt Name unique constraint violated
API-->>C: 409 Conflict (Subcategory name already exists)
else Other constraint violations
API-->>C: 409 Conflict (per existing checks)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
app/migrated_routes/category.py(1 hunks)app/migrated_routes/subcategory.py(1 hunks)tests/test_category.py(2 hunks)tests/test_product.py(2 hunks)tests/test_subcategory.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/test_product.py (1)
tests/conftest.py (3)
create_product(87-98)client(14-21)create_authenticated_headers(43-55)
tests/test_subcategory.py (2)
tests/conftest.py (3)
create_subcategory(72-83)client(14-21)create_authenticated_headers(43-55)app/migrated_routes/subcategory.py (1)
put(161-244)
tests/test_category.py (2)
tests/conftest.py (3)
create_category(59-68)client(14-21)create_authenticated_headers(43-55)app/migrated_routes/category.py (1)
put(153-221)
🔇 Additional comments (8)
app/migrated_routes/category.py (1)
207-212: LGTM! Duplicate name handling aligns with POST.The duplicate name detection for PUT is correctly implemented and mirrors the existing POST behavior. The check is appropriately placed before the linkage constraint check, ensuring specific error messages for each violation type.
tests/test_product.py (2)
73-82: LGTM! Header handling refactor improves clarity.The change separates creation (using fixture default authentication) from mutation (explicit inline authentication), making the authentication requirements clearer at the call site.
92-99: LGTM! Consistent with update test refactoring.The DELETE test follows the same header handling pattern as the update test, maintaining consistency across the test suite.
app/migrated_routes/subcategory.py (1)
225-230: LGTM! Mirrors category implementation.The duplicate name handling for subcategory PUT is correctly implemented and consistent with both the category PUT logic and the subcategory POST logic.
tests/test_subcategory.py (2)
77-86: LGTM! Header handling consistent with product tests.The refactoring aligns with the pattern established in test_product.py, separating creation authentication (implicit) from mutation authentication (explicit).
115-122: LGTM! Delete test follows consistent pattern.The header handling refactor is consistent with the update test and aligns with the broader test suite changes.
tests/test_category.py (2)
77-86: LGTM! Header handling aligns with test suite pattern.The refactoring is consistent with the changes in test_product.py and test_subcategory.py.
116-123: LGTM! Delete test follows suite-wide pattern.The header handling refactor maintains consistency with the update test and other test files in the PR.
Summary by CodeRabbit
New Features
Bug Fixes
Tests