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

Using Dry Run throws a key error #536

Closed
arky opened this issue Jan 9, 2024 · 2 comments · Fixed by #538
Closed

Using Dry Run throws a key error #536

arky opened this issue Jan 9, 2024 · 2 comments · Fixed by #538
Labels
bug Something isn't working
Milestone

Comments

@arky
Copy link

arky commented Jan 9, 2024

The problem

A description of what the bug is, including a complete traceback (if applicable)

Expected behavior

Setting 'dry_run' to true results in a key error. However it would run correctly without it.

Steps to reproduce the behavior

 enable_logging()
    
    create_observation(
        taxon_id=40268, 
        observed_on_string=time,
        time_zone="Bangkok",
        latitude="10.6122382",
        longitude="104.1774368",
        description=" some description",
        access_token=token,
        dry_run=True
        )
[01-09 15:48:17] INFO     Request: (DRY RUN)                                                         [session.py](file:///usr/local/lib/python3.10/dist-packages/pyinaturalist/session.py):[297](file:///usr/local/lib/python3.10/dist-packages/pyinaturalist/session.py#297)
                          POST https://api.inaturalist.org/v1/observations?ignore_photos=1                         
                          User-Agent: python-requests/2.31.0 pyinaturalist/0.19.0                                  
                          Accept-Encoding: gzip, deflate, br                                                       
                          Accept: application/json                                                                 
                          Connection: keep-alive                                                                   
                          Authorization: [REDACTED]                                                                
                          Content-Length: 201                                                                      
                          Content-Type: application/json                                                           
                          {'observation': {'taxon_id': 40268, 'observed_on_string':                                
                          '2023-12-17T18:27:29+07:00', 'time_zone': 'Bangkok', 'description': ' some               
                          description', 'latitude': '10.6122382', 'longitude': '104.1774368'}}                     

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[17], line 17
     14 print(time)
     15 enable_logging()
---> 17 create_observation(
     18     taxon_id=40268, 
     19     observed_on_string=time,
     20     time_zone="Bangkok",
     21     latitude="10.6122382",
     22     longitude="104.1774368",
     23     description=" some description",
     24     access_token=token,
     25     dry_run=True
     26     )

File /usr/local/lib/python3.10/dist-packages/forge/_revision.py:328, in Revision.__call__.<locals>.inner(*args, **kwargs)
    324 @functools.wraps(callable)  # type: ignore
    325 def inner(*args, **kwargs):
    326     # pylint: disable=E1102, not-callable
    327     mapped = inner.__mapper__(*args, **kwargs)
--> 328     return callable(*mapped.args, **mapped.kwargs)

File /usr/local/lib/python3.10/dist-packages/pyinaturalist/v1/observations.py:418, in create_observation(**params)
    416 response = post(f'{API_V1}/observations', json={'observation': params}, **kwargs)
    417 response_json = response.json()
--> 418 observation_id = response_json['id']
    420 upload(observation_id, photos=photos, sounds=sounds, photo_ids=photo_ids, **kwargs)
    421 return response_json

KeyError: 'id'

Workarounds

Is there an existing workaround for this issue?

Environment

  • OS & version: Ubuntu LTS
  • Python version: 10.2.1
  • Pyinaturalist version or branch: 0.19
@JWCook
Copy link
Member

JWCook commented Jan 10, 2024

Thanks for the bug report. This has been fixed in main.

@JWCook JWCook added this to the v0.19 milestone Jan 10, 2024
@arky
Copy link
Author

arky commented Jan 13, 2024

Thank you @JWCook Much appreciated.

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

Successfully merging a pull request may close this issue.

2 participants