#nukesforbreakfast_unexpected

1 messages ยท Page 1 of 1 (latest)

arctic roostBOT
#

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

๐Ÿ“ 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.

frail meadow
#
  • advance the test clock into the middle of march
#

Why did in_1S6MQJBlHXHWwVN7Ya0GQqrN get created at the same time as in_1S6LxkBlHXHWwVN7SK41Jloh under subscription sub_1S6LxkBlHXHWwVN77Rqbw0mh?

half hedge
#

hi there ๐Ÿ‘‹ give me awhile to catch up

frail meadow
#

no problem. I probably did something wrong. ๐Ÿ˜…

#

the invoice items that were pending before the final test clock advancement: 'ii_1S6MDABlHXHWwVN7XZfCppEQ', 'ii_1S6MCwBlHXHWwVN7xWv3autA'

half hedge
#

Thanks for waiting while I looked at sub_1S6LxkBlHXHWwVN77Rqbw0mh ! To confirm โ€” when the subscription was created, its pending_invoice_item_interval is set to monthly.

The test clock time when sub_1S6LxkBlHXHWwVN77Rqbw0mh and the invoice item ii_1S6MDABlHXHWwVN7XZfCppEQ is created is 2025-02-07 00:00:00 UTC .

Since pending invoice item interval is set to bill monthly, it make sense that the one-time invoice (in_1S6MQJBlHXHWwVN7Ya0GQqrN) will be created together with the subscription's invoice (in_1S6LxkBlHXHWwVN7SK41Jloh) as the subscription enters its first cycle.

frail meadow
#

is this because the subscription's invoice wasn't finalized yet when I added the invoice item?

#

because that subscription was created on the same test clock time of 2025-02-07 00:00:00 UTC as when the invoice item was created. I had forgotten to advance it to finalize the invoice automatically.

#

though the invoice item call came after the subscription call.

half hedge
#

Hmm..could you share with me the product behaviour you expected?

frail meadow
#

I had expected when I advanced into March, the monthly invoice for pending items would be created on March 1, since the subscription was backdated to January 1.

half hedge
#

No I believe it is because the subscription has not entered its first active cycle when the pending invoice item was created

frail meadow
#

I have no idea what that means ๐Ÿ˜…

half hedge
#

give me a moment to run tests your scenario

frail meadow
#

I'm going to also run it again but advance the test clock a few days in feb before creating the invoice items.

half hedge
#

Hmm I wasn't able to reproduce the same behaviour but i did notice your invoice item and subscription were created almost at the same time

#

could you create the subscription first, then create the invoice item, then advance your test clock into the next month

frail meadow
#

I think it was because the test clock was at the same frozen time when the subscription and invoice items were created.

#

when I advanced the test clock by a couple days after creating the second subscription, I then created the invoice items. I then advanced the test clock into March and the invoices were created on March 1 as expected.

#

let me do another test and see if it's the test clock or invoice finalization.

half hedge
#

I only advanced my test clock after I created my backdated subscription and pending invoice item. The pending invoice item is then invoiced in the subscription's next period. Let me know how your test goes

frail meadow
#

so I ended up in a very weird state.

half hedge
#

could you share the new subscription id

frail meadow
#

cus_T2SRtsNjjGuH7x

#

sub_1S6NWCBcr0GkEvwYDTmW8Xlt

#

sub_1S6NWiBcr0GkEvwYFrzrhV4t

#

I somehow ended up with 5 invoices instead of 4

#

and one of them has both subscription fees on it.

#

it seems some weird things happen if pending invoice items get created at the same time.

#

this is my full script:

import stripe
import boto3
from decouple import config
from test.factories import (
    AccountFactory,
    InvoiceItemFactory,
    PermitFeeProductFactory,
    PermitRenewalFeeProductFactory,
    TestClockFactory,
    CustomerFactory,
    SubscriptionFactory,
    SubscriptionScheduleFactory,
)
from datetime import datetime, timezone
from time import sleep

stripe_client = stripe.StripeClient(
    boto3.client("secretsmanager").get_secret_value(
        SecretId=config("STRIPE_SECRET_ID")
    )["SecretString"]
)
account = AccountFactory(stripe_test_client=stripe_client)
test_clock = TestClockFactory(
    stripe_test_client=stripe_client,
    stripe_account=account.id,
    frozen_time=int(datetime(2025, 1, 15, tzinfo=timezone.utc).timestamp()),
)
customer = CustomerFactory(
    stripe_test_client=stripe_client,
    stripe_account=account.id,
    test_clock=test_clock.id,
)
subscription = SubscriptionFactory(
    stripe_test_client=stripe_client,
    stripe_account=account.id,
    customer=customer,
    backdate_start_date=int(datetime(2025, 1, 1, tzinfo=timezone.utc).timestamp()),
)

test_clock = stripe_client.v1.test_helpers.test_clocks.advance(
    test_clock.id,
    {"frozen_time": int(datetime(2026, 2, 15, tzinfo=timezone.utc).timestamp())},
    options={"stripe_account": account.id},
)
while test_clock.status == "advancing":
    sleep(5)
    test_clock = test_clock.refresh()
#
subscription2 = SubscriptionFactory(
    stripe_test_client=stripe_client,
    stripe_account=account.id,
    customer=customer,
    backdate_start_date=int(datetime(2025, 2, 1, tzinfo=timezone.utc).timestamp()),
    items__0__price_data__product=subscription["items"].data[0].price.product,
)
invoice = stripe_client.v1.invoices.finalize_invoice(
    subscription2.latest_invoice, options={"stripe_account": account.id}
)
invoice_item = InvoiceItemFactory(
    stripe_test_client=stripe_client,
    stripe_account=account.id,
    customer=subscription.customer,
    invoice=None,
    subscription=subscription.id,
)
invoice_item2 = InvoiceItemFactory(
    stripe_test_client=stripe_client,
    stripe_account=account.id,
    customer=subscription2.customer,
    invoice=None,
    subscription=subscription2.id,
)

test_clock = stripe_client.v1.test_helpers.test_clocks.advance(
    test_clock.id,
    {"frozen_time": int(datetime(2026, 3, 2, tzinfo=timezone.utc).timestamp())},
    options={"stripe_account": account.id},
)
while test_clock.status == "advancing":
    sleep(5)
    test_clock = test_clock.refresh()
#

no I see the issue I think I messed up the test clock advancement times

#

one second

half hedge
#

One of your subscription (sub_1S6NWCBcr0GkEvwYDTmW8Xlt) is really odd because I am seeing many numerous update events on it that changing the next_pending_invoice_item_invoice timestamp.

I will need more time to look into this. Would it be okay if I drop you a DM that creates a case with my team and we'll look into this async

frail meadow
#

hang on, let me try my test case with the test clock advancing to the next year issue fixed.

#

ok, that worked when I didn't create the invoice items at the same exact time as the 2nd subscription. Let me see if it reproduces when I do.

#

worked as expected that time.

#

ok, so I'm not seeing the issue anymore.

half hedge
#

great, so not creating the invoice item at the same time as the second subscription fixed it

frail meadow
#

well, even though I did it didn't reproduce this time.

#

so IDK if it's a race condition that only triggers sometimes.

half hedge
#

I'm not sure either because I can't reproduce it on my end. We can further investigate if it can be consistently reproduced and sharing with us the steps to do it

frail meadow
#

I think we're good for now.

half hedge
#

okay let us know if you run into anything else unexpected