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

Infinite Loop when syncing a Customer and PaymentMethod #1125

Closed
czue opened this issue Feb 27, 2020 · 5 comments
Closed

Infinite Loop when syncing a Customer and PaymentMethod #1125

czue opened this issue Feb 27, 2020 · 5 comments
Assignees
Labels
webhook / sync issues Errors or Issues with webhooks, sync_from_stripe_data etc
Milestone

Comments

@czue
Copy link
Contributor

czue commented Feb 27, 2020

Describe the bug

Calling sync_from_stripe_data from a newly created Customer object in stripe is creating an infinite loop.

To Reproduce

By following the Stripe docs - create a PaymentMethod in stripe via elements and then try to create a Customer in the backend:

    customer = stripe.Customer.create(
      payment_method=payment_method,  # from request
      email=email,  # from request
      invoice_settings={
        'default_payment_method': payment_method,
      },
    )

    # this call hangs forever
    djstripe_customer = djstripe.models.Customer.sync_from_stripe_data(customer)

I added some print statements to StripeModel._get_or_create_from_stripe_object to see what was going on and basically it just keeps bouncing back and forth like this:

get or create from stripe object: <class 'djstripe.models.core.Customer'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH
get or create from stripe object: <class 'djstripe.models.core.Customer'> pm_1GGhFqIYTEfulA0yB7etKVBt
get or create from stripe object: <class 'djstripe.models.payment_methods.PaymentMethod'> cus_GoJtPNFHEqy7uH

Expected behavior

I would ideally expect it to create the Customer and PaymentMethod once.

If that's too difficult then I would expect it to raise an Exception when it hits a recursive creation.

Environment

  • dj-stripe version: 2.2.2.
  • Your Stripe account's default API version: 2019-12-03
  • Database: Postgres 10
  • Python version: 3.5.2
  • Django version: 2.2.10

Can you reproduce the issue with the latest version of master?

I haven't tried yet.

@czue czue added the webhook / sync issues Errors or Issues with webhooks, sync_from_stripe_data etc label Feb 27, 2020
@czue
Copy link
Contributor Author

czue commented Feb 27, 2020

note: a workaround for this is to just create the djstripe PaymentMethod before creating the Customer in stripe

    payment_method_obj = stripe.PaymentMethod.retrieve(payment_method)
    djstripe.models.PaymentMethod.sync_from_stripe_data(payment_method_obj)
    stripe.Customer.create(...)

@therefromhere
Copy link
Contributor

Hi thanks for the report, that's not good.

@ogu2
Copy link

ogu2 commented Mar 22, 2020

Ran into this too

@nickromanooo
Copy link

I am seeing this as well. My issue was related to having multiple developers local environments hooked up to the same Stripe environment. Customer update events would trigger this if they weren't in the local with correct djstripe_id.

@jleclanche jleclanche added this to the 2.5.0 milestone Nov 13, 2020
@jleclanche jleclanche modified the milestones: 2.5.0, 2.4.x Feb 8, 2021
@jleclanche jleclanche modified the milestones: 2.4.x, 2.6.0 Jun 6, 2021
@arnav13081994
Copy link
Member

Closed by #1387

@arnav13081994 arnav13081994 self-assigned this Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
webhook / sync issues Errors or Issues with webhooks, sync_from_stripe_data etc
Projects
None yet
Development

No branches or pull requests

6 participants