rienafairefr / pynYNAB

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

client crashing with TypeError if there are future transactions #25

Closed tlastowka closed 7 years ago

tlastowka commented 7 years ago

The current version of the client seems to be crashing any time there the budget in question has any future transactions scheduled.

I want to believe this has something to do with my environment and not nYNABapi itself, but even when I stripped it down to a bare minimum script with a brand new minimal budget it seems to be the case. nYNABapi was installed this morning per the readme from the master branch.

I'm happy to provide additional data if needed.

Bare minimum script

from pynYNAB.Client import clientfromargs
import configargparse

parser = configargparse.getArgumentParser('pynYNAB')
args = parser.parse_args()
args.email = 'someone@example.com'
args.password = 'some_password'
args.budgetname = 'some_budget'
client = clientfromargs(args)
client.sync()

print(client.budget_name)

Working: Sample budget with no future transaction

screenshot 2016-12-16 13 41 40

ssh://vagrant@127.0.0.1:2222/home/vagrant/venv/bin/python3 -u /vagrant/issue_example.py
some_budget

Process finished with exit code 0

Not Working: The exact same budget with a transaction happening tomorrow.

screenshot 2016-12-16 13 55 55

ssh://vagrant@127.0.0.1:2222/home/vagrant/venv/bin/python3 -u /vagrant/issue_example.py
Traceback (most recent call last):
  File "/vagrant/1.py", line 9, in <module>
    client = clientfromargs(args)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Client.py", line 16, in clientfromargs
    return nYnabClient.from_obj(args,reset)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Client.py", line 48, in from_obj
    client = nYnabClient(connection, budget_name=args.budgetname)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Client.py", line 42, in __init__
    self.sync()
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Client.py", line 80, in sync
    self.sync_obj(self.budget, 'syncBudgetData', knowledge=False,extra=dict(calculated_entities_included=False,budget_version_id=self.budget_version_id))
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Client.py", line 130, in sync_obj
    self.update_from_sync_data(obj,sync_data)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Client.py", line 109, in update_from_sync_data
    obj.update_from_changed_entities(changed_entities)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Entity.py", line 173, in update_from_changed_entities
    getattr(self, namefield).update_from_changed_entities(changed_entities.get(namefield))
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Entity.py", line 226, in update_from_changed_entities
    self._update_hashes()
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Entity.py", line 199, in _update_hashes
    self._dict_entities_hash = {hash(v): v for k, v in self._dict_entities.items()}
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB-0.3-py3.5.egg/pynYNAB/Entity.py", line 199, in <dictcomp>
    self._dict_entities_hash = {hash(v): v for k, v in self._dict_entities.items()}
TypeError: __hash__ method should return an integer

Process finished with exit code 1

Environment Information:

(venv) vagrant@vagrant:~$ cat /etc/issue
Ubuntu 16.04.1 LTS \n \l
(venv) vagrant@vagrant:~$ uname -a
Linux vagrant 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
(venv) vagrant@vagrant:~$ python -V
Python 3.5.2
(venv) vagrant@vagrant:~$ pip freeze
aenum==1.4.5
appdirs==1.4.0
cchardet==1.1.1
click==6.6
ConfigArgParse==0.11.0
configparser==3.5.0
dateparser==0.5.0
enum34==1.1.6
et-xmlfile==1.0.1
ezodf==0.3.2
future==0.16.0
ijson==2.3
jdatetime==1.8.1
jdcal==1.3
jsonlines==1.1.0
jsonschema==2.5.1
jsontableschema==0.8.4
linear-tsv==1.0.0
lxml==3.7.0
openpyxl==2.4.1
pkg-resources==0.0.0
pynab==0.6.8
pynYNAB==0.3
python-dateutil==2.6.0
pytz==2016.10
regex==2016.11.21
requests==2.12.4
rfc3986==0.4.1
ruamel.yaml==0.13.4
schematics==2.0.0a1
six==1.10.0
tabulator==0.12.1
toolz==0.8.2
tzlocal==1.3
umalqurra==0.2
unicodecsv==0.14.1
xlrd==1.0.0
rienafairefr commented 7 years ago

Hi, I think, don't blame your environnement, blame the master branch ^^ ... I don't get enough time to work on it, and there's been regressions in the last few commits in the master. I'm looking into it, the 0.2 version on pypi should be functional enough, I hope. Sorry about that, AFAIK the error is shown, I've overloaded hash to sort/compare entities/transactions etc, and apparently it's not working well... Thanks for the report and sorry about the inconvenience.

tlastowka commented 7 years ago

No worries! It just seemed like a nice way to automate some things I deal with in ynab manually right now. That anyone is working on this stuff at all is great!

tlastowka commented 7 years ago

For what its worth, I don't think this issue appeared in 0.3. I rolled a clean environment and installed 0.2 from pypi and still get the same error. Still, think this thing is neat!

Traceback (most recent call last):
  File "1.py", line 10, in <module>
    client = clientfromargs(args)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Client.py", line 17, in clientfromargs
    client = nYnabClient(connection, budget_name=args.budgetname)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Client.py", line 45, in __init__
    self.sync()
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Client.py", line 71, in sync
    self.budget.sync(self.connection, 'syncBudgetData')
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/roots.py", line 61, in sync
    self.update_from_changed_entities(changed_entities)
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Entity.py", line 173, in update_from_changed_entities
    getattr(self, namefield).update_from_changed_entities(changed_entities.get(namefield))
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Entity.py", line 226, in update_from_changed_entities
    self._update_hashes()
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Entity.py", line 199, in _update_hashes
    self._dict_entities_hash = {hash(v): v for k, v in self._dict_entities.items()}
  File "/home/vagrant/venv/lib/python3.5/site-packages/pynYNAB/Entity.py", line 199, in <dictcomp>
    self._dict_entities_hash = {hash(v): v for k, v in self._dict_entities.items()}
TypeError: __hash__ method should return an integer
(venv) vagrant@vagrant:/vagrant$ pip freeze
aenum==1.4.5
appdirs==1.4.0
cchardet==1.1.1
click==6.6
ConfigArgParse==0.11.0
dateparser==0.5.0
enum34==1.1.6
et-xmlfile==1.0.1
ezodf==0.3.2
future==0.16.0
ijson==2.3
jdatetime==1.8.1
jdcal==1.3
jsonlines==1.1.0
jsonschema==2.5.1
jsontableschema==0.8.4
linear-tsv==1.0.0
lxml==3.7.0
ofxtools==0.3.13
openpyxl==2.4.1
pkg-resources==0.0.0
pynab==0.6.8
pynYNAB==0.2
python-dateutil==2.6.0
pytz==2016.10
regex==2016.11.21
requests==2.12.4
rfc3986==0.4.1
ruamel.yaml==0.13.4
schematics==1.1.1
six==1.10.0
tabulator==0.12.1
toolz==0.8.2
tzlocal==1.3
umalqurra==0.2
unicodecsv==0.14.1
xlrd==1.0.0
rienafairefr commented 7 years ago

Hi tlastowka, What's the status of this issue with recent versions (the ones using sqlalchemy for object relation management) ?