-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscription Items are not retrievable with items
-attribute on Subscription object
#297
Comments
Not my brainchild, so thank @ob-stripe -- but an easy fix might be: @property
def subcription_items(self):
return self['items']
@subscription_items.setter
def subscription_items(self, value):
self['items'] = value |
Thanks for opening this @anelder-stripe! So I guess that the two critiques I'd have of the accessor approach are:
I'm not sure if I have a good alternative, but maybe even recommending the use of |
Even though I'm the one who suggested the accessor approach, I'm not too thrilled about adding aliases either -- esp. because it'd be very hard to properly document those. The annoying part with the existing state is that you can use sub = stripe.Subscription.retrieve('sub_...')
sub.items = [{'plan': '10monthly'}]
sub.save()
# At this point, the subscription item is refreshed with the values returned by the API
# and the items attribute is reassigned to dict's items() function.
sub.items
# <built-in method items of Subscription object at 0x10f83fe30>
sub['items']
# <ListObject list at 0x11041aab8> JSON: {...} It's largely a matter of opinion, but I'd argue that preserving getter/setter consistency is more important than preserving the We could define an |
@ob-stripe Cool, thanks! I dunno. I think you're right, but I can't get behind the idea of overwriting built-in methods, even though we're almost certainly doing it elsewhere in Ruby and such. The best thing that I can think of right now might be to start implementing server-side naming checks for common programming language names and maybe start phasing these ones out with API versioning. |
I'll go ahead and close this issue since it doesn't sound like we have a better client-side fix other than the existing workaround (i.e. using Hopefully in the next major version of stripe-python, |
Why is the issue closed if the workaround isn't clear in the documentation? I'm just trying to update Subscription plan quantities... |
Just ran into this as well, in case that's a helpful data point. Took me a while to find this issue. |
4 years later I this thread saved me ... |
Having subscription items accessible only via I ended up creating a def create_stripe_subscription(self):
subscription = unittest.mock.MagicMock(
spec=stripe.Subscription,
# ...
)
subscription["items"].data = [
unittest.mock.Mock(
spec=stripe.SubscriptionItem,
# ...
)
)
return subscription Not nice. |
There is an additional problem here because the python types allow you to write If I do this |
The Subscriptions object now has a new attribute on it
items
that represent the Subscription Items (AKA Multiple Plans) associated with a Subscription. Unfortunately, there is a method on Python Dictionaries calleditems()
and it is causing conflicts.For anyone who runs into this-- as a work around, you can retrieve the items using
sub['items']
.I recommend we rename the parsed
items
-contents when we're deserializing the JSON and associate it instead with asubscription_items
-attribute then update our documentation accordingly for Python.The text was updated successfully, but these errors were encountered: