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

Add returned letter callback celery tasks #4369

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

BlessedDev
Copy link
Contributor

This PR adds the celery tasks needed for the returned letter callback feature as described in this card.

@BlessedDev BlessedDev marked this pull request as ready for review February 3, 2025 16:48
# queue callback task only if the service_callback_api exists
if service_callback_api := get_service_returned_letter_callback_api_for_service(service_id=data.service_id):
reported_date = get_returned_letter_reported_at_date_by_notification_id_dao(data.id)
returned_letter_data = create_returned_letter_callback_data(reported_date, service_callback_api)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried running any of this code, but spotted that create_returned_letter_callback_data has three required arguments and yet is being called with only two here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I will update the function call.

Copy link
Contributor

@klssmith klssmith Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also make sure this would get caught by the tests

returned_letter_data = fetch_returned_letter_data(service_id, reported_date)

data = {
"notification_id": str(returned_letter_data[0]["notification_id"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have got this wrong, but from looking at the code it appears that this create_returned_letter_callback_data function is called once per returned letter, gets all the returned letters for the relevant service and yet only ever returns the first one. So if a service had 5 returned letters, its callback endpoint would be hit 5 times but every time they would receive details of the first letter.

I have tried to test this locally to see if this is the case, but am getting SQLAlchemy errors from this function which I haven't had a chance to dig into. This needs some thorough local testing to check everything is working as expected.

Copy link
Contributor Author

@BlessedDev BlessedDev Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@klssmith Yes, you are right, only details for the first letter is being retrieved. I will address that and also update the test cases as the two bugs you noticed should have been picked up by unit tests.

@BlessedDev BlessedDev marked this pull request as draft February 6, 2025 09:55
@BlessedDev
Copy link
Contributor Author

I am having a rethink of my approach in this PR and will be overhauling most of it.

 This helper function  initiates returned letters callback for services
 that have the feature enabled.
 This method retrieves the data for the returned letter callback. It mirrors the information provided in the returned letter report.
@BlessedDev BlessedDev force-pushed the add_returned_letter_callback_celery_tasks branch from 25c0131 to 15d3530 Compare February 7, 2025 16:36
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.

3 participants