Skip to content

Commit

Permalink
Merge pull request #389 from stripe/ob-fix-388
Browse files Browse the repository at this point in the history
Register unsaved attributes on assignment regardless of new value
  • Loading branch information
brandur-stripe committed Jan 12, 2018
2 parents 4b951cb + 601ea29 commit 30801d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
9 changes: 4 additions & 5 deletions stripe/stripe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ def __setitem__(self, k, v):
"You may set %s.%s = None to delete the property" % (
k, str(self), k))

if not hasattr(self, k) or v != getattr(self, k):
# Allows for unpickling in Python 3.x
if not hasattr(self, '_unsaved_values'):
self._unsaved_values = set()
# Allows for unpickling in Python 3.x
if not hasattr(self, '_unsaved_values'):
self._unsaved_values = set()

self._unsaved_values.add(k)
self._unsaved_values.add(k)

super(StripeObject, self).__setitem__(k, v)

Expand Down
27 changes: 23 additions & 4 deletions tests/api_resources/abstract/test_updateable_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def setUp(self):
'post',
'/v1/myupdateables/myid',
{
'thats': 'it'
'id': 'myid',
'thats': 'it',
}
)

Expand Down Expand Up @@ -83,17 +84,35 @@ def test_save(self):
self.checkSave()
self.assert_no_request()

# Setting the same value should not cause any request.
# Setting the same value should cause a request.
self.stub_request(
'post',
'/v1/myupdateables/myid',
{
'id': 'myid',
'thats': 'it',
}
)

self.obj.thats = 'it'
self.checkSave()
self.assert_no_request()

self.assert_requested(
'post',
'/v1/myupdateables/myid',
{
'thats': 'it',
},
None
)

# Changing the value should cause a request.
self.stub_request(
'post',
'/v1/myupdateables/myid',
{
'thats': 'it'
'id': 'myid',
'thats': 'it',
}
)

Expand Down

0 comments on commit 30801d1

Please sign in to comment.