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

source-stripe-native: handle responses for children of deleted resources #1982

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

Alex-Bair
Copy link
Contributor

@Alex-Bair Alex-Bair commented Sep 26, 2024

Description:

Child streams, like InvoiceLineItems perform incremental replication by watching for events on their associated parent resource, then requesting all child resources for that parent when an event happens. However, since there can be some time between when we process an event & what actually happens in Stripe, it's possible for us to request child resources of a deleted parent. Stripe returns a 404 code and somewhat unique text to indicate this. We can safely skip requesting these resources when this happens.

This situation can happen if a creation/update is quickly followed by a deletion. If the connector is stuck for a while and a backlog of events we haven't processed builds up, there's even more opportunity for us to request deleted resources.

I noticed this issue happening with InvoiceLineItems, so I also removed the "invoice.deleted" event from that stream's EVENT_TYPES since we'll just get an error back if we request a deleted invoice's line items.

Workflow steps:

(How does one use this feature, and how has it changed)

Documentation links affected:

(list any documentation links that you created, or existing ones that you've identified as needing updates, along with a brief description)

Notes for reviewers:

Tested on a local stack. Confirmed that requesting children of a deleted parent resource no longer crashes the connector & that the connector continues processing after handling the error.


This change is Reviewable

@Alex-Bair Alex-Bair added the change:unplanned Unplanned change, useful for things like doc updates label Sep 26, 2024
@Alex-Bair Alex-Bair requested a review from a team September 26, 2024 15:56
Copy link
Member

@psFried psFried left a comment

Choose a reason for hiding this comment

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

LGTM

# the requests for the associated child resources fail. Stripe returns a 404
# error & a message containing "resource_missing" and "No such" when this happens.
if err.code == 404 and bool(re.search(MISSING_RESOURCE_REGEX, err.message, re.DOTALL)):
log.debug(f"Missing resource error for URL {child_url}. Skipping to the next resource.", err)
Copy link
Member

Choose a reason for hiding this comment

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

IDK how common it is to get 404 responses, but it might be helpful to log at info or warn levels as long as it wouldn't be too spammy. Feel free to ignore this suggestion if it'd result in a bunch of log spam though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, Phil! I don't anticipate we'd encounter this error all that often. I'll switch it over to warn.

Child streams, like `InvoiceLineItems` handle incremental replication by
watching for events on their associated parent resource, then requesting
all child resources for that parent. However, since there can be some
time between when we process an event & what actually happens in Stripe,
it's possible for us to request child resources of a deleted parent.
Stripe returns a `404` code and somewhat unique text to indicate this.
We can safely skip requesting these child resources when this happens.

I noticed this issue happening with `InvoiceLineItems`, so I also
removed the "invoice.deleted" event from that stream's `EVENT_TYPES`
since we'll just get an error back if we ask for a deleted parent
resource's children.
@Alex-Bair Alex-Bair force-pushed the bair/source-stripe-native-invoice-lines-events branch from d531ba7 to 9ef1a88 Compare September 26, 2024 18:15
@Alex-Bair Alex-Bair merged commit 78a1761 into main Sep 26, 2024
67 of 76 checks passed
@Alex-Bair Alex-Bair deleted the bair/source-stripe-native-invoice-lines-events branch September 26, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:unplanned Unplanned change, useful for things like doc updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants