#nukesforbreakfast_api

1 messages ยท Page 1 of 1 (latest)

plucky citrusBOT
#

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

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

hollow flume
#

in this case you'd probably just need to make a separate call to retrieve the account

frigid warren
#

alright, I was hoping there was some way to auto expand it since the python SDK seems to attach a stripe_account id to the object when it's retrieved from another connected account.

plucky citrusBOT
tawdry wren
#

hello ๐Ÿ‘‹ taking over the thread from my colleague. Our API doesn't auto-expand and there's some parameters that can't be expanded. If you need to retrieve a Stripe account, you'd want to use this endpoint: https://docs.stripe.com/api/accounts/retrieve

frigid warren
#

where does the stripe_account attribute on objects come from in the Python SDK?

#
>>> hasattr(invoice, "stripe_account")
True
>>> invoice.stripe_account
'acct_1S1GBOBYo5ujVKCc'
tawdry wren
#

The Invoice object itself doesn't have a stripe_account attribute, though it is possible to determine the Stripe account through other params like the hosted_invoice_url and invoice_pdf

frigid warren
#

it looks like it comes as a property of the StripeObject.

#

which is a python SDK specific thing

#

I think this might be a Pydantic bug, but I guess I'll ask anyways if y'all have ever seen this.

tawdry wren
#

I can do a test, were you just retrieving your invoice?

frigid warren
#
from pydantic import BaseModel, ConfigDict
import stripe

class ExampleModel(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    stripe_account: str


class Example:
    @property
    def stripe_account(self):
        return "foo"


# This works as expected.
example_obj = Example()
print(ExampleModel.model_validate(example_obj))

# This fails unexpectedly
stripe_obj = stripe.StripeObject(stripe_account="acct_asdf")
print(ExampleModel.model_validate(stripe_obj))
#

yes

#
>>> hasattr(invoice, "stripe_account")
True
>>> invoice.stripe_account
'acct_1S1GBOBYo5ujVKCc'
>>> ExampleModel.model_validate(invoice)
Traceback (most recent call last):
  File "<python-input-37>", line 1, in <module>
    ExampleModel.model_validate(invoice)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/rccausey/.cache/pypoetry/virtualenvs/billing-api--M5yUIBR-py3.13/lib/python3.13/site-packages/pydantic/main.py", line 705, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        obj, strict=strict, from_attributes=from_attributes, context=context, by_alias=by_alias, by_name=by_name
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ExampleModel
stripe_account
  Field required [type=missing, input_value=<Invoice invoice id=in_1S...ivered_at": 1756427358
}, input_type=Invoice]
    For further information visit https://errors.pydantic.dev/2.11/v/missing
#

I was trying to pass the invoice object into a Pydantic model, and pull out the stripe_account field.

#

for some reason Pydantic is not working here. I do notice that the types are set up kind of weird in the Python SDK where the invoices service casts a StripeObject to an Invoice.

#

The versions of the libraries are:

stripe = "12.5.0"
pydantic = "2.11.7"

#

I just wanted to know if y'all have a known incompatiblity between the objects that the Stripe Python SDK puts out and Pydantic, or if this should be filed as a bug against the Pydantic repo.

frigid warren
tawdry wren
#

Stripe don't have official support for the Pydantic library but its possible that the library created a wrapper around Stripe objects based on our tests, but I can't advised much on this.

For the most accurate information on retrieving Stripe objects, please use our Stripe's Python Library [0] and our API Docs [1] . This is from our Python library for the Invoice object, and it does not contain the Stripe account ID: https://github.com/stripe/stripe-python/blob/master/stripe/_invoice.py

[0] https://docs.stripe.com/sdks
[1] https://docs.stripe.com/api

frigid warren
#

Pydantic is really just a parsing and validation library

#

so it's not wrapping stripe directly.

#

but the StripeObject that the stripe python SDK does have the stripe_account property.

#

I was just using it to transform the returned invoice data into the correct shape for our GraphQL API.

#

so to be clear my code is using the Stripe API to retrieve the invoice object:

stripe_invoice = stripe_client.v1.invoices.retrieve(
    node_info.id,
    params={"expand": ("customer",)},
    options=merge_default_options({"stripe_account": node_info.account_id}),
)
#

it's just that the use of Pydantic to transform the invoice into the return structure is not working as expected, and I'm guessing it has to do with some Python typing dark magic going on between how the Stripe Python SDK gets generated and what Pydantic is looking for:

return Invoice.model_validate(stripe_invoice).model_dump(
    mode="json", by_alias=True
)