Error when accessing invoice.lines.data's item.subscription_item if the item is not a subscription item.

Open
#1,459 7 comments 0 reactions 1 assignee View on GitHub

@jar-stripe is already working on this.

Since Mar 3, 2025.

Assessment

This issue has not been assessed yet.

Description

bug
Describe the bug

When accessing item.subscription_item, I expect a None value but instead I get an Exception.

To Reproduce
stripe_invoice = stripe_repo.retrieve_stripe_invoice(existing_stripe_subscription.latest_invoice)
for item in stripe_invoice.lines.data:
     if item.subscription_item: # this throws an error if the item is not a subscription_item
        pass
Expected behavior

The expectation is that defaults to None if not a subscription_item.

(variable) subscription_item: ExpandableField[SubscriptionItem] | None
The subscription item that generated this line item. Left empty if the line item is not an explicit result of a subscription.

Code snippets

OS

macOS

Language version

Python 3.12.8

Library version

stripe 11.5.0

API version

2025-01-27.acacia

Additional context

No response

Dominant language
Python
Stars
2k
Forks
539
Avg merge
2d 7h
Merged PRs (30d)
26

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stripe/stripe-python

All issues in stripe/stripe-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.