Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix adding duplicate officers to incidents (#1006)
## Description of Changes Merging fix OrcaCollective#347 upstream. **Original PR description**: Only add new officers to incidents. When a user edits an incident currently, we retrieve the Incident from the database and append all officers in the form to that Incident. This led to sqlalchemy trying to insert duplicate rows into the officer_incidents association table. As far as I can tell, this was silently ignored by sqlalchemy in the past and no unexpected rows were created. With the upgrade to sqlalchemy 2.0.19 (OrcaCollective#344), the library appears to have started raising exceptions related to this behavior. This change checks to see whether an officer already exists in Incident.officers before adding them so as to not add duplicate officers. ## Notes for Deployment N/A ## Screenshots (if appropriate) N/A ## Tests and linting - [x] This branch is up-to-date with the `develop` branch. - [x] `pytest` passes on my local development environment. - [x] `pre-commit` passes on my local development environment.
- Loading branch information