question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite recursion when webhook gets called

See original GitHub issue

Describe the bug When the dj-stripe webhook gets called, it enters an infinite recursion which eventually raises an exception with the message “maximum recursion depth exceeded while calling a Python object”

To Reproduce

  1. Install dj-stripe
  2. Put Stripe into “view test data” mode so we can work with test data. settings.STRIPE_LIVE_MODE should be False
  3. Point your stripe account to use at your server’s /stripe/webhook/ endpoint as a webhook
  4. Using test mode, purchase a subscription using your application, or re-send a failed webhook attempt of type invoice.payment_succeeded (not sure if this happens for other event types)
  5. Watch the dj-stripe webhook get called (ProcessWebhookView.post), but this call never completes, as the code enters an infinite recursion

I can set a breakpoint in djstripe.models.core.Event.invoke_webhook_handlers and when I try to step over the line of code webhooks.call_handlers(event=self), the code goes into an infinite recursion which eventually times out. I am including a portion of this stack trace (the same lines repeat over and over since it’s an infinite recursion). I am also attaching the event JSON.

Expected behavior Successful processing of webhook.

Environment

  • dj-stripe version: master
  • Your Stripe account’s default API version: 2020-03-02
  • Database: Postgres
  • Python version: 3.6.2
  • Django version: 3.0.2

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

Yes

Additional context Here is a snippet of the repeating stack trace, and the event data is attached to this ticket as a file.

  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 340, in _stripe_object_field_to_foreign_key
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 532, in _get_or_create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 430, in _create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 239, in _stripe_object_to_record
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 340, in _stripe_object_field_to_foreign_key
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 532, in _get_or_create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 430, in _create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 239, in _stripe_object_to_record
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 340, in _stripe_object_field_to_foreign_key
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 532, in _get_or_create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 430, in _create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 239, in _stripe_object_to_record
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 340, in _stripe_object_field_to_foreign_key
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 532, in _get_or_create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 430, in _create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 239, in _stripe_object_to_record
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 340, in _stripe_object_field_to_foreign_key
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 532, in _get_or_create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 430, in _create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 239, in _stripe_object_to_record
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 340, in _stripe_object_field_to_foreign_key
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 532, in _get_or_create_from_stripe_object
    stripe_account=stripe_account,
  File "/Users/ghassett/.virtualenvs/wwapiserver/lib/python3.6/site-packages/djstripe/models/base.py", line 430, in _create_from_stripe_object
    stripe_account=stripe_account,

event.txt

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
arnav13081994commented, Sep 14, 2021

Hi @lmeyerov

The fix is in master but not in the latest release yet. It should land in the next release.

2reactions
jleclanchecommented, Jan 16, 2021

I’ll be able to work on this Sunday and next week. Sorry for the delays everyone, this has been a busy new years period.

Read more comments on GitHub >

github_iconTop Results From Across the Web

infinite loop in a WebHook - Stack Overflow
I'm doing a facebook messenger bot. After you start it, it makes a call to WebHook. Unfortunately after the first start will not...
Read more >
OnUpdate webhook how to prevent infinite loop?
Hi,. I am using issue update event for a webhook to call a 3rd party service. On such events, the 3rd party service...
Read more >
Question about nitpicky detail on dealing with infinite loop ...
I think I understand that a webhook "Callback" is itself comprised of several "Callback Events", each of which may have its own changeAgent ......
Read more >
I need help identifying possible recursion causing a rate limit ...
I've got the following web hook that gets called when an item is created. To test it I am passing in command line...
Read more >
Webhook Infinite Loop - Shopify Community
My app is 100% of the time returning a 200 response code, I don't know why I'm being spammed with webhook calls. 1,552...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found