rienafairefr / pynYNAB

a python client for the new YNAB
MIT License
138 stars 12 forks source link

nYnabClient.sync fails #33

Closed hfaran closed 7 years ago

hfaran commented 7 years ago

from pynYNAB.connection import nYnabConnection
from pynYNAB.Client import nYnabClient

nconn = nYnabConnection(email="redacted", password="redacted")
nc = nYnabClient(budgetname="redacted", nynabconnection=nconn)

nc.sync()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-34-14dc614db2a6> in <module>()
----> 1 nc.sync()

d:\anaconda\lib\site-packages\pynYNAB\Client.pyc in sync(self)
    260         self.sync_catalog()
    261         self.select_budget(self.budget_name)
--> 262         self.sync_budget()
    263 
    264         if self.budget_version_id is None and self.budget_name is not None:

d:\anaconda\lib\site-packages\pynYNAB\Client.pyc in sync_budget(self)
    251 
    252     def sync_budget(self):
--> 253         self.budgetClient.sync(extra=self.extra_budget)
    254 
    255     def sync(self):

d:\anaconda\lib\site-packages\pynYNAB\Client.pyc in sync(self, extra)
    103         self.client.logger.debug('server_knowledge_of_device ' + str(sync_data['server_knowledge_of_device']))
    104         self.client.logger.debug('current_server_knowledge ' + str(sync_data['current_server_knowledge']))
--> 105         self.update_from_sync_data(sync_data)
    106         self.session.commit()
    107         self.obj.clear_changed_entities()

d:\anaconda\lib\site-packages\pynYNAB\Client.pyc in update_from_sync_data(self, sync_data)
     95 
     96     def update_from_sync_data(self, sync_data):
---> 97         self.update_from_api_changed_entities(sync_data['changed_entities'])
     98 
     99     def sync(self, extra=None):

d:\anaconda\lib\site-packages\pynYNAB\Client.pyc in update_from_api_changed_entities(self, changed_entities)
     62             newlist = []
     63             for entitydict in changed_entities[name]:
---> 64                 newlist.append(self.obj.listfields[name].from_apidict(entitydict))
     65             changed_entities[name] = newlist
     66         self.update_from_changed_entities(changed_entities)

d:\anaconda\lib\site-packages\pynYNAB\schema\Entity.pyc in from_apidict(cls, entityDict)
    228             if column.name in entityDict and entityDict[column.name] is not None:
    229                 conversion_function = fromapi_conversion_functions_table.get(column.type.__class__, lambda t, x: x)
--> 230                 modified_dict[column.name] = conversion_function(column.type, entityDict[column.name])
    231         return cls.from_dict(modified_dict)
    232 

d:\anaconda\lib\site-packages\pynYNAB\schema\Entity.pyc in <lambda>(t, x)
    165     Date: date_from_api,
    166     AmountType: lambda t, x: x / 1000,
--> 167     sqlaEnum: lambda t, x: t.enum_class[x]
    168 }
    169 

d:\anaconda\lib\site-packages\aenum\__init__.pyc in __getitem__(cls, name)
    913 
    914     def __getitem__(cls, name):
--> 915         return cls._member_map_[name]
    916 
    917     def __iter__(cls):

KeyError: u'PayPal'

If it helps: "PayPal" is indeed one of my account names, and it is active.

rienafairefr commented 7 years ago

from what I can see, pynynab searches for 'Paypal' as an account type, in the Account class you have this property

account_type = Column(Enum(AccountTypes), default=AccountTypes.undef)

and the AccountTypes enum is:

class AccountTypes(Enum):
    undef = 'undef'
    Checking = 'Checking'
    Savings = 'Savings'
    CreditCard = 'CreditCard'
    Cash = 'Cash'
    LineOfCredit = 'LineOfCredit'
    Paypal = 'Paypal'
    MerchantAccount = 'MerchantAccount'
    InvestmentAccount = 'InvestmentAccount'
    Mortgage = 'Mortgage'
    OtherAsset = 'OtherAsset'
    OtherLiability = 'OtherLiability'

there is a typo ! Paypal should be PayPal Thanks for the bug report. I'll fix this soon

rienafairefr commented 7 years ago

let me know if the issue is not fixed