Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Passed data doesn't have all required keys (missing keys: created) #28

Closed
karlicoss opened this issue Mar 16, 2022 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@karlicoss
Copy link

pymonzo version: v0.11.0 (latest)

This started happening for me since 15.03.2022:

Stacktrace:

  ...
  File "/app/export.py", line 44, in <genexpr>                                                                                                                                                                                                                
    self.api.transaction(t['id'], expand_merchant=True)._raw_data
  File "/usr/local/lib/python3.8/site-packages/pymonzo/monzo_api.py", line 398, in transaction                                                                                                                                                                
    return MonzoTransaction(data=response.json()['transaction'])                                                                                                                                                                                              
  File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 42, in __init__                                                                                                                                                                  
    self._parse_special_fields(data_copy)                                                                                                                                                                                                                     
  File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 117, in _parse_special_fields                                                                                                                                                    
    self.merchant = MonzoMerchant(data=data.pop('merchant'))                                                                                                                                                                                                  
  File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 33, in __init__                                                                                                                                                                  
    raise ValueError(                                                                                                                                                                                                                                         
ValueError: Passed data doesn't have all required keys (missing keys: created)

More debugging:

DEBUG:requests_oauthlib.oauth2_session:Passing through key word arguments {'params': {'expand[]': 'merchant'}, 'allow_redirects': True}.
DEBUG:urllib3.connectionpool:https://api.monzo.com:443 "GET /transactions/tx_XXXXXXXXXXXXXXX?expand%5B%5D=merchant HTTP/1.1" 200 None
(Pdb) self.api._get_response(method='get', endpoint=f"/transactions/{transactions[0]['id']}", params={'expand[]': 'merchant'}).json()['transaction']['merchant']
{'id': 'merch_0000A7F9qhxKe3RynPV14E', 'group_id': 'grp_000092JZy7UcN7FpKMkvh3', 'name': 'Deliveroo', 'logo': 'https://mondo-logo-cache.appspot.com/twitter/deliveroo/?size=large', 'emoji': '🍝🦘', 'category': 'eating_out', 'online': True, 'atm': False, 'address': {'short_formatted': 'Somewhere in the United Kingdom', 'city': '', 'latitude': 54.557817, 'longitude': -3.484688, 'zoom_level': 4, 'approximate': True, 'formatted': 'United Kingdom', 'address': '', 'region': '', 'country': 'GBR', 'postcode': ''}, 'disable_feedback': False, 'suggested_tags': '#groceries #food, #delivery #yum', 'metadata': {'suggested_tags': '#groceries #food, #delivery #yum', 'website': 'www.deliveroo.co.uk'}

So merchant creation date is missing from the payload. I couldn't find API docs for merchants, so not sure if it's just not passed by the API now

Possibly related: monzo/docs#71

I tried monkey patching it with the following snippet:

M_keys = MonzoMerchant._required_keys                                                                                                                                                                                                                     
if 'created' in M_keys:                                                                                                                                                                                                                                   
    M_keys.remove('created')                                                                                                                                                                                                                              

But sadly this fails with, so seems created is hardcoded in pymonzo code

 File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 117, in _parse_special_fields
    self.merchant = MonzoMerchant(data=data.pop('merchant'))
  File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 42, in __init__
    self._parse_special_fields(data_copy)
  File "/usr/local/lib/python3.8/site-packages/pymonzo/api_objects.py", line 136, in _parse_special_fields
    self.created = parse_date(data.pop('created'))
KeyError: 'created`

So I think for now, for my monzoexport, I'll just use the raw __get_response method. But let me know if you're interested in a proper fix, I might come up with some PR. Thanks!

@pawelad pawelad self-assigned this Feb 4, 2024
@pawelad pawelad added the bug Something isn't working label Feb 4, 2024
@pawelad pawelad added this to the v1.0.0 milestone Feb 4, 2024
@pawelad
Copy link
Owner

pawelad commented Feb 4, 2024

First of all, sorry for replying so late. The library was essential not supported since ~2017. I had some free time recently though and decided to give it some love and release v1.0.0
I tried reproducing the error, and I think it’s fixed. I’m gonna close the issue, but let me know if it still errors out.

@pawelad pawelad closed this as completed Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants