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.

TypeError: argument of type 'NoneType' is not iterable (Direct charge on connected account)

See original GitHub issue

Describe the bug

[11/Feb/2022 20:07:50] "GET /activity/6/ HTTP/1.1" 200 28154[11/Feb/2022 20:07:50] "GET /activity/6/ HTTP/1.1" 200 28154
Not Found: /media/users/e4808681-7aa4-46db-94bf-529c05cfb703-da7cf183cd34cfdea373b48d24e62787.jpg
[11/Feb/2022 20:07:50] "GET /media/users/e4808681-7aa4-46db-94bf-529c05cfb703-da7cf183cd34cfdea373b48d24e62787.jpg HTTP/1.1" 404 35258
> /home/you/workshop/Django/xdemo/clubs/club_dashboard.py(1284)post()
-> customer_obj, created = Customer.objects.get_or_create(new_customer, stripe_account=club.stripe_connect_trader_account_id)
(Pdb) Internal Server Error: /xdemo_stripe/webhook/
Traceback (most recent call last):
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/views.py", line 36, in post
    trigger = WebhookEventTrigger.from_request(request)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/webhooks.py", line 217, in from_request
    raise e
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/webhooks.py", line 203, in from_request
    obj.process(save=False)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/webhooks.py", line 294, in process
    self.event = Event.process(self.json_body)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/core.py", line 1525, in process
    ret.invoke_webhook_handlers()
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/core.py", line 1537, in invoke_webhook_handlers
    webhooks.call_handlers(event=self)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/webhooks.py", line 98, in call_handlers
    handler_func(event=event)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/event_handlers.py", line 73, in customer_webhook_handler
    if event.customer and target_object_type == "customer":
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/core.py", line 1567, in customer
    return Customer._get_or_retrieve(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 988, in _get_or_retrieve
    instance = cls.sync_from_stripe_data(data)
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 946, in sync_from_stripe_data
    instance, created = cls._get_or_create_from_stripe_object(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 704, in _get_or_create_from_stripe_object
    cls._create_from_stripe_object(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 574, in _create_from_stripe_object
    stripe_data = cls._stripe_object_to_record(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 356, in _stripe_object_to_record
    field_data, skip, is_nulled = cls._stripe_object_field_to_foreign_key(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 469, in _stripe_object_field_to_foreign_key
    field_data, _ = field.related_model._get_or_create_from_stripe_object(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/payment_methods.py", line 123, in _get_or_create_from_stripe_object
    source_cls._get_or_create_from_stripe_object(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 704, in _get_or_create_from_stripe_object
    cls._create_from_stripe_object(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 574, in _create_from_stripe_object
    stripe_data = cls._stripe_object_to_record(
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 321, in _stripe_object_to_record
    if not cls.is_valid_object(data):
  File "/home/you/workshop/Django/xdemo/venv/lib/python3.8/site-packages/djstripe/models/base.py", line 493, in is_valid_object
    return "object" in data and data["object"] == cls.stripe_class.OBJECT_NAME
TypeError: argument of type 'NoneType' is not iterable

To Reproduce I was getting “Application fee” issue on

  1. Upgraded djstripe from 2.5.0 to 2.6.1 because I was getting application_fee errors on webhook.
  2. Run the below code
token = stripe.Token.create(
    customer=request.user.stripe_customer_id,
    stripe_account=stripe_account,
)

customer = stripe.Customer.create(
    name=request.user.email,
    email=request.user.email,
    source=token.id,
    stripe_account=stripe_account,
)

payment_intent = stripe.PaymentIntent.create(
    amount=int(price * 100),
    currency='GBP',
    customer=customer.id,
    payment_method=customer.default_source,
    payment_method_types=['card'],
    application_fee_amount=int(price * 100 * settings.STRIPE_APPLICATION_FEE_PERCENTAGE),
    stripe_account=f'{stripe_account}',
)

Environment

  • dj-stripe version: [2.6.1]
  • Database: [postgres 12]
  • Python version: [e.g. 3.8.10]
  • Django version: [e.g. 3.2.5]

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
arnav13081994commented, May 2, 2022

@janbaykara you could write your own webhook handler to handle such webhook connect events.

1reaction
janbaykaracommented, May 1, 2022

What can be done as a workaround for now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: argument of type 'NoneType' is not iterable
The Python "TypeError: argument of type 'NoneType' is not iterable" occurs when we use the membership test operators (in and not in) with...
Read more >
argument of type 'NoneType' is not iterable on airflow auth ...
My understanding is user is returned empty from OIDC server but as we try to iterate on it, it fails because None is...
Read more >
Python TypeError: 'NoneType' object is not iterable Solution | CK
For an object to be iterable, it must contain a value. A None value is not iterable because it does not contain any...
Read more >
argument of type 'NoneType' is not iterable when testing core ...
TypeError : argument of type 'NoneType' is not iterable when testing core ... I don't know if it's a bug or how to...
Read more >
Django Object Has No Attribute Get - LU.SE.CA. s.r.l. Oristano
Django Object Has No Attribute GetRelated Pages Python Functions Tutorial Function Call a Function Function Arguments *args Keyword Arguments Default ...
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