Closed eppercut closed 1 year ago
@eppercut - does https://github.com/eppercut/splitwise/tree/fix-attrs resolve this enough?
Well this is one problem yes, but we would need to resolve all the objects here including repayments, receipt etc. I will have a look at it. Splitwise update API says that you should only send the fields you want to update.
So for now, you can create a new expense object from the expense object you get from the server.
Hi @namaggarwal. I am having the same issue TypeError: 'User' object is not iterable
with both updateExpense and createExpense methods. What I wanted to do is to update the percentage of the repayments for several of my expenses, do it manually would take very long. And I thought to do it by updating the existing expenses or by deleting them and then creating new ones, with the correct values. Is there a workaround that i am not seeing it? Thanks!
I am releasing a fix for it soon. Splitwise API has stopped accepting adhoc params, so I deleted other params and also added a test
Fixed in v3.0.0
@ocamposfaria You would need to calculate the owed_share and paid_share and then update it for all the expenses
@namaggarwal I did as you said! Thanks for your help, I really appreciate the effort :)
The
User
class overrides__getattr__
to returnNone
(link).I am not sure why this is, but a side effect is that when you check for the existence of magic methods, instead of receiving a real answer, it simply returns
None
.This, in turn, means that Requests is not able to encode
User
objects, when called in methods likeupdateExpense
. This is due to this line. Due to the override, whenval
is aUser
object,not hasattr(val, '__iter__')
evaluates toFalse
, instead of returningTrue
like it logically should.As a result, the
User
object that is the value ofcreated_by
is not wrapped in a list, but instead Requests tries to iterate on it directly andupdateExpense
fails. I'm not sure howupdateExpense
was ever able to work for anyone.Reproduction:
my_script.py
Console
Value of
expense_data
when it is POSTed via__makeRequest
(line)The problem is the
User
object which is the value ofcreated_by
, since as explained above, Requests cannot properly check if it is iterable.I am not sure why
User
andExpense
classes override__getattr__
and none of the other classes do. However, it seems like the solution would be to at least not override properly checking for magic methods.