Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding duplicate officers to incidents #1006

Merged

Conversation

sea-kelp
Copy link
Collaborator

@sea-kelp sea-kelp commented Aug 3, 2023

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

  • This branch is up-to-date with the develop branch.
  • pytest passes on my local development environment.
  • pre-commit passes on my local development environment.

@michplunkett
Copy link
Collaborator

Looks good to me! If possible, it'd be nice to have a migration that removes any duplicates, though I'd also be happy to write that after this is merged.

@michplunkett michplunkett merged commit cb63dfe into lucyparsons:develop Aug 3, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants