Return 400 for duplicate device permissions and pinned devices
๐ Looking for an issue? Welcome! This issue is open for contribution. If this is the first time youโre requesting an issue, please:
- Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that donโt follow the guidelines wonโt be answered.
- Confirm that youโve read the guidelines in your comment.
Overview
Creating a device permission or a pinned device that already exists returns a 500 from the database's unique constraint. In both serializers the field the constraint covers isn't a plain model field, so DRF doesn't add its unique validator. These should return a 400.
Complexity: Low Target branch: develop
Context
On develop at fe298f5449:
POST /api/device/devicepermissions/for a user who already has a device permissions row raisesIntegrityError.device_permissions.py#L10declaresuserexplicitly. (superuser)POST /api/discovery/pinned_devices/with the sameinstance_idtwice raisesIntegrityError.pinned_device.py#L15-L25setsuseroutside the serializer. (learner)
The Change
- Each serializer should validate uniqueness for the fields its database constraint covers.
Acceptance Criteria
- [ ] Each request under Context returns 400 and leaves the existing row unchanged.
- [ ] Tests cover both duplicate creates.
AI usage
I had Claude Code sweep Kolibri's API code for unvalidated request input and reproduce each 500 with a test. I chose the fix and the split into sub-issues. Claude Code drafted the issue to the pattern of #15838.
Hi! ๐
This issue is available for contribution and supports self-assignment. Here's how to get started:
- Comment
/assignto assign yourself to this issue - You can have up to 2 issues assigned at a time across all community repos
- Dropping an issue has a 7-day cooldown before the slot opens up
- Link your pull request to this issue when you submit it
๐ Read the Contributing guidelines before starting.
Are you preparing for Google Summer of Code? See our GSoC guidelines.
/assign
Hi! ๐
You've been assigned to this issue. Here's what to do next:
- Read the issue description carefully and make sure you understand the requirements
- Link your pull request to this issue when you submit it
- If you can no longer work on this, unassign yourself so others can pick it up
Good luck! ๐
Are you preparing for Google Summer of Code? See our GSoC guidelines.
/unassign
Since @RajvanshSingh4 has already submitted a PR
Hi @adibmbrk, I'm unassigning you from this issue so that you can pick up other issues. @RajvanshSingh4, please comment on this issue if you want to be assigned. In the future, you must follow our contribution guidelines.
Hi, please assign me.
Hi! ๐
Thanks for your interest! This issue supports self-assignment. Comment /assign to assign yourself.
Visit Contributing guidelines to learn about the contributing process. ๐
Are you preparing for Google Summer of Code? See our GSoC guidelines.