the-scouts / compass-interface-core

Core bridge/crawler component for Compass-Interface
5 stars 1 forks source link

Error with people.latest_disclosure #50

Closed arbitrarypunter closed 3 years ago

arbitrarypunter commented 3 years ago

Trying to use people.latest_disclosure form 0.9.5, but its bombing with this error:

Traceback (most recent call last): File "/home/agoodall/compass/scripts/test-single.py", line 29, in max_disc = people.latest_disclosure(member_id) File "/home/agoodall/compass/devenv/lib/python3.9/site-packages/compass/core/people.py", line 200, in latest_disclosure date_map = {disc: disc.expiry_date for disc in disclosures if disc.expiry_date} File "/home/agoodall/compass/devenv/lib/python3.9/site-packages/compass/core/people.py", line 200, in date_map = {disc: disc.expiry_date for disc in disclosures if disc.expiry_date} TypeError: unhashable type: 'MemberDisclosure'

My python as you know isn't good enough to fully debug it, but with the below diff for compass/core/people.py i was able to get it working.

200,201c200 < date_map = {disc: disc.expiry_date for disc in disclosures if disc.expiry_date} < return date_map.get(max(date_map.keys(), default=None))

    return  max(disclosure.expiry_date for disclosure in disclosures if disclosure.expiry_date)

I haven't submitted this as a PR as you were obviously handling it in a different manner for a reason and i imagine the real fix to your intended code is probably trivial.

AA-Turner commented 3 years ago

Aha this is slightly embarrasing, it should be the other way around - disc.expiry_date : disc ...

Thanks for reporting, shows that should really work on #6 and find a way to fake out Compass or something

AA-Turner commented 3 years ago

Done, as you said trivial - the reason it raised an exception is that keys in python dictionaries can be almost anything, as long as they are hashable (which usually also means immutable). In this case BaseModel derived classes are not hashable/immutable, leading to the exception.

The logical error was that I wanted to map dates to disclosure objects and get the highest, and as you saw had them backwards!