fix(accounts): improve customer deletion flow and handle relationship constraints#86
Merged
CFBruna merged 29 commits intov2/monorepo-migrationfrom Feb 21, 2026
Conversation
…ccounts orchestrators
…d authorization features
- Make Customer.user nullable and SET_NULL - Add email and name to Customer for anonymous or walk-in customers - Update CustomerService to support Flow A (with email/user) and Flow B (no user) - Update CustomerViewSet, serializers, and forms for new flows - Fix related typing issues in other apps - Update tests to reflect new requirements and edge cases
- Add write-only name to CustomerSerializer - Simplify perform_create fallback logic to only use serializer validated_data - Simplify __str__ of Customer model - Update CustomerService.quick_register docstring - Fix test for Customer __str__ without user
…pled Customer/User backend
…ervice, remove email from Flow 2
…an Customer on shop registration
…nd i18n - Create ShopLoginPage and ShopProfilePage - Introduce useShopLogin hook for token generation - Refactor PublicLayout Header to dynamically render user DropdownMenu upon authentication - Add 'Remember Me' inputs for native browser credential savings - Add complete en/pt/es translations for accounts, layout, and registration
- Remove validate_email, validate_phone, and validate_tax_id from CustomerSerializer - Correct has_permission in CustomerPermission to handle register actions
- Revert shop profile routes to /shop/profile - Replace any-types and English assertions in useRegistrationForm with correct defaults - Replace hardcoded SelectItems in CustomerForm and RegistrationForm with translations - Insert missing generic i18n keys for accounts fields and shop flows into locale bundles
- Fix default remember parameter in AuthContext to prevent unwanted persistence - Pass remember=false to login upon registration in useAuthMutations - Implement localStorage persistence for login identifier in useShopLogin - Replace any casting with LoginApiError type in useShopLogin error handling
- Catch ProtectedError in CustomerViewSet destroy method - Return 400 Bad Request with a human-readable message instead of 500 Server Error when attempting to delete a customer with linked records (e.g., pets or sales)
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.
What Changed
accounts/views.py): Overrode thedestroymethod inCustomerViewSetto catch Django'sProtectedError. Customers with associated relationships (pets, sales) now return a clean400 Bad Requestinstead of triggering a500 Internal Server Error.features/accounts/hooks/useCustomers.ts): AddedonSuccessandonErrorhandlers to thedeleteCustomermutation, triggering localized Toast notifications.features/accounts/components/CustomerList): Replaced the nativewindow.confirmdialog with a responsive and accessible Shadcn UIDialogfor the delete confirmation step.delete_successanddelete_errorinternationalization keys across English, Portuguese, and Spanish translation files.tests/test_forms.py&store/tasks.py): Resolved lingering validation errors inPetAdminFormtests and patched BanditB311security warnings by moving pseudo-random generation tosecrets.Why
When attempting to delete a Customer that had linked entities (such as pets or sales), the backend threw an unhandled
ProtectedError, causing a 500 server crash with no UI feedback for the user in the shop interface. This PR implements a safe deletion lifecycle: confirming the action gracefully in the UI, catching relational database constraints, and providing clear, localized error/success toast feedback.How to Test
uv run pytestand verify theaccountsandpetstest suites pass.npm run lintand verify no ESLint warnings remain.Checklist
uv run pytestpassesnpm run buildpasses