websideproject / paddle-billing-client

Python wrapper around the new Paddle Billing API
MIT License
14 stars 6 forks source link

PaddleApiClient.get_subscription("sub_xxxx") produces validation error if discount.starts_at is None #363

Closed wmp3 closed 4 months ago

wmp3 commented 4 months ago

šŸ› Bug Report

when PaddleApiClient.get_subscription("sub_xxxx") is called subscriptions has an associated Discount, Pydantic throws an error if discount.starts_at is None. I think starts_at could be None if for example customer uses a discount during trial but cancels before a paid subscription starts.

Here's the error message I get:

ValidationError: 3 validation errors for list_subscriptions data.7.discount.starts_at Input should be a valid datetime [type=datetime_type, input_value=None, input_type=NoneType] For further information visit https://errors.pydantic.dev/2.7/v/datetime_type

šŸ”¬ How To Reproduce

Steps to reproduce the behavior:

I'm not exactly sure how to reproduce via PaddleApiClient but maybe something like:

  1. create a SubscriptionDiscount with starts_at == None
  2. create a SubscriptionBase with SubscriptionBase.discount = SubscriptionDiscount
  3. update Subscription on Paddle via API?
  4. try to fetch all subscriptions from paddle API via PaddleApiClient.list_subscriptions()

Code sample

If the following small change doesn't break any tests, I think the bug can be fixed by changing https://github.com/websideproject/paddle-billing-client/blob/main/paddle_billing_client/models/subscription.py from:

class SubscriptionDiscount(BaseModel):
    id: str
    starts_at: datetime
    ends_at: datetime | None = None

to:

class SubscriptionDiscount(BaseModel):
    id: str
    starts_at: datetime | None = None
    ends_at: datetime | None = None

Environment

Screenshots

šŸ“ˆ Expected behavior

no pydantic validation error

šŸ“Ž Additional context

github-actions[bot] commented 4 months ago

Hello @wmp3, thank you for your interest in our work!

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

bgervan commented 4 months ago

Indeed, the starts at is optional https://developer.paddle.com/api-reference/subscriptions/get-subscription

Fixed in: https://github.com/websideproject/paddle-billing-client/releases/tag/v0.2.10