Commit cb63dfe
authored
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.1 parent 6a27393 commit cb63dfe
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1626 | 1626 | | |
1627 | 1627 | | |
1628 | 1628 | | |
1629 | | - | |
| 1629 | + | |
1630 | 1630 | | |
1631 | 1631 | | |
1632 | 1632 | | |
| |||
0 commit comments