Skip to content

Commit cb63dfe

Browse files
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

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

OpenOversight/app/main/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ def populate_obj(self, form, obj):
16261626
except ValueError:
16271627
our_id = officer["oo_id"].split('value="')[1][:-2]
16281628
of = Officer.query.filter_by(id=int(our_id)).first()
1629-
if of:
1629+
if of and of not in obj.officers:
16301630
obj.officers.append(of)
16311631

16321632
license_plates = form.data.pop("license_plates")

0 commit comments

Comments
 (0)