Skip to content

Commit

Permalink
[Justice Counts] Pass user email into `copy_metric_settings_and_alert…
Browse files Browse the repository at this point in the history
…_user` (Recidiviz/recidiviz-data#29439)

## Description of the change

Patches [the error that was surfaced in
Sentry](https://recidiviz-inc.sentry.io/issues/5278901581/?project=4504532096516096&query=is%3Aunresolved&referrer=issue-stream&stream_index=0)
this afternoon. Long story short, `args` was not passed into
`copy_metric_settings_and_alert_user` as a parameter but was referenced
anyway.

I tested by running the script with the changes in the staging
environment and locally and verifying that it ran without errors.

## Checklists

### Development

**This box MUST be checked by the submitter prior to merging**:
- [x] **Double- and triple-checked that there is no Personally
Identifiable Information (PII) being mistakenly added in this pull
request**

These boxes should be checked by the submitter prior to merging:
- [ ] Tests have been written to cover the code changed/added as part of
this pull request

### Code review

These boxes should be checked by reviewers prior to merging:

- [ ] This pull request has a descriptive title and information useful
to a reviewer
- [ ] Potential security implications or infrastructural changes have
been considered, if relevant

GitOrigin-RevId: 97e78197734579eee753039d4875a20ee77ca67b
  • Loading branch information
nichelle-hall authored and Helper Bot committed May 14, 2024
1 parent 67b2fef commit 08b104c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@
current_session=session,
agency_name=args.agency_name,
send_grid_client=send_grid_client,
user_email=args.user_email,
)
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def copy_metric_settings_and_alert_user(
agency_name: str,
metric_definition_key_subset: List[str],
current_session: Session,
user_email: str,
send_grid_client: SendGridClientWrapper,
child_agency_id_subset: Optional[List[int]] = None,
) -> None:
Expand Down Expand Up @@ -403,21 +404,21 @@ def copy_metric_settings_and_alert_user(
except Exception as e:
logging.exception("Failed to copy metric settings: %s", e)
send_grid_client.send_message(
to_email=args.user_email,
to_email=user_email,
from_email="no-reply@justice-counts.org",
from_email_name="Justice Counts",
subject=f"Unfortunately, your request to copy {args.agency_name}'s (ID: {args.super_agency_id}) metric settings to its child agencies could not be completed.",
html_content=f"""<p>Sorry, something went wrong while attempting to copy the metric settings from {args.agency_name} (ID: {args.super_agency_id}). Please reach out to a member of the Recidiviz team to help troubleshoot.</p>""",
subject=f"Unfortunately, your request to copy {agency_name}'s (ID: {super_agency_id}) metric settings to its child agencies could not be completed.",
html_content=f"""<p>Sorry, something went wrong while attempting to copy the metric settings from {agency_name} (ID: {super_agency_id}). Please reach out to a member of the Recidiviz team to help troubleshoot.</p>""",
disable_link_click=True,
unsubscribe_group_id=UNSUBSCRIBE_GROUP_ID,
)
else:
# Send confirmation email once metrics have been successfully copied over
send_grid_client.send_message(
to_email=args.user_email,
to_email=user_email,
from_email="no-reply@justice-counts.org",
from_email_name="Justice Counts",
subject=f"Your request to copy {args.agency_name}'s (ID: {args.super_agency_id}) metric settings to its child agencies has been completed.",
subject=f"Your request to copy {agency_name}'s (ID: {super_agency_id}) metric settings to its child agencies has been completed.",
html_content=success_html_content,
disable_link_click=True,
unsubscribe_group_id=UNSUBSCRIBE_GROUP_ID,
Expand Down Expand Up @@ -453,4 +454,5 @@ def copy_metric_settings_and_alert_user(
current_session=session,
agency_name=args.agency_name,
send_grid_client=email_client,
user_email=args.user_email,
)

0 comments on commit 08b104c

Please sign in to comment.