#adambirds_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1407420103313854628
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- adambirds_code, 2 hours ago, 7 messages
At the time off the error, Sentry is saying stripe_subscription contains the following:
{
application: None,
application_fee_percent: None,
automatic_tax: {
disabled_reason: None,
enabled: False,
liability: None
},
billing_cycle_anchor: 1758195653,
billing_cycle_anchor_config: None,
billing_mode: {
type: "classic"
},
billing_thresholds: None,
cancel_at: None,
id: "sub_1Rxnur2LmMGMEfX03ifBg5l8",
object: "subscription"
}
hi! taking a look at this now
I'm just going to add some more logs in and redploy as well.
ok, just to make sure i understand, you're trying to grab the current_period_start from a subscription after retrieving it and you're running into this error?
can you explain what you mean by "after recent update"?
did you change API versions or something like that?
ok yes i saw from the previous thread
this was after updating to basil
Yes. So my full code is this. I recieve an invoice payment succeded webhook event and then I need to grab the current period start/end/trial end:
def handle_invoice_payment_succeeded(event: Dict[str, Any], webhook_event: WebhookEvent) -> None:
invoice = event["data"]["object"]
customer_id = invoice["customer"]
subscription_id = invoice["subscription"]
subscription, created = Subscription.objects.get_or_create(
customer=Customer.objects.get(stripe_customer_id=customer_id),
)
stripe_subscription: stripe.Subscription = stripe.Subscription.retrieve(subscription_id)
logger.info(f"Processing invoice payment succeeded for subscription {subscription_id}")
logger.info(f"Stripe subscription details: {stripe_subscription}")
logger.info(f"Stripe subscription items: {stripe_subscription.items.data}")
subscription.stripe_subscription_id = subscription_id
subscription.status = stripe_subscription.status
subscription.current_period_start = datetime.fromtimestamp(
stripe_subscription.items.data[0].current_period_start
)
subscription.current_period_end = datetime.fromtimestamp(
stripe_subscription.items.data[0].current_period_end
)
subscription.trial_end = (
datetime.fromtimestamp(stripe_subscription.trial_end)
if stripe_subscription.trial_end
else None
)
subscription.save()
## Check if created at time is close to now to avoid sending renewal email at signupm so if created at time is say in last 30 mins dont send renewal email
if not created and subscription.created_at < timezone.now() - timedelta(minutes=30):
send_successful_subscription_renewal_email.delay(
subscription.customer.user.email, subscription.customer.user.first_name
)
webhook_event.processed = True
webhook_event.save()
Yes after updating to basil. Previously just stripe_subscription.current_period_start worked.
Not sure if it would help, but I can share the error in sentry which shows the full trace etc.
nah, i have a lead on what's going on
gimme just a bit to dig, i'll let you know if i need any more info from you ๐
No worries.
here's the changelog where this is documented:
https://docs.stripe.com/changelog/basil/2025-03-31/deprecate-subscription-current-period-start-and-end
so you should instead look at items.data[0].current_period_end
which you're doing
let me look at your code
i don't think you need to expand or do anything fancy to access this data....
can you try retrieving the subscription real quick using cURL / postman / a quick script or something like that? and paste the response body here
https://docs.stripe.com/api/subscriptions/retrieve
i see you included the subscription state reported by sentry but that looks off to me
so i'm curious what our API says if you access it directly right now
ok yep i see that the current_period_start is in there
But when I do this on that object:
subscription.items.data[0].current_period_start
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'data'
let me try real quick
Ahh, accessing like this works:
>>> subscription["items"].data[0].current_period_start
1755616920
yep i was thinking it would probably be something like that, was just spinning up a test script
i've been writing python for a long time and sometimes accessing object properties is still a little mysterious to me ๐
Yeah I do wonder if it needs making clearer anywhere in the docs. As even the intellisense acts like doing .items should work fine.
i can take a look to see where might be a good place to call that out!
Yeah, and thanks for the help. For future is it possible to upgrade the library to the new version but still make API calls by specifiying an old version whilst we test it for a few days?
yep! let me look up the docs on that
Yeah so, I think this may actually be a bug in the library or at least with the types defined. As when like this stripe_subscription["items"].data it think data is Any type whereas when it is like stripe_subscription.items.data it shows the correct tyoe of List[SubscriptionItem] however that gets the builtin_function_or_method error.
you can specify API versions on a request level like this:
https://github.com/stripe/stripe-python?tab=readme-ov-file#per-request-configuration
you can also specify the API version more broadly like so:
stripe.api_version = "2025-06-30.basil"
although i'm struggling to find where we document that ๐
wait it's just here:
https://docs.stripe.com/api/versioning?lang=python
Sweet will make a note of that for future.
yep of course!
For this bit as I think its an actual bug, shall i raise an issue on github for this.
oo i completely missed that message, 1 sec
ok yeah, i think raising a github issue directly makes sense for that
Yeah great, will do. Thanks for the help today.