#adambirds_code

1 messages ยท Page 1 of 1 (latest)

median jacinthBOT
#

๐Ÿ‘‹ 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.

indigo linden
#

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"
}
rotund sapphire
#

hi! taking a look at this now

indigo linden
#

I'm just going to add some more logs in and redploy as well.

rotund sapphire
#

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

indigo linden
#

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.

rotund sapphire
#

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 ๐Ÿ™‚

indigo linden
#

No worries.

rotund sapphire
rotund sapphire
#

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....

#

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

indigo linden
#

Yeah 2 secs

rotund sapphire
#

ok yep i see that the current_period_start is in there

indigo linden
#

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'

rotund sapphire
#

let me try real quick

indigo linden
#

Ahh, accessing like this works:

>>> subscription["items"].data[0].current_period_start
1755616920
rotund sapphire
#

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 ๐Ÿ˜…

indigo linden
rotund sapphire
#

i can take a look to see where might be a good place to call that out!

indigo linden
#

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?

rotund sapphire
#

yep! let me look up the docs on that

indigo linden
#

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.

rotund sapphire
#

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 ๐Ÿ˜…

indigo linden
#

Sweet will make a note of that for future.

rotund sapphire
#

yep of course!

indigo linden
rotund sapphire
#

oo i completely missed that message, 1 sec

#

ok yeah, i think raising a github issue directly makes sense for that

indigo linden
#

Yeah great, will do. Thanks for the help today.