Apply default_params to client.taxa(id)
synrg opened this issue · 3 comments
The problem
It appears that the default params set on the client are not sent when you use the taxa controller to fetch a taxon by its ID#, causing some fields in the resulting taxon object to not be set to expected values.
Expected behavior
When I set a preferred place in the client defaults, and then look up a taxon by id# that has an establishment means, I expect the resulting taxon object to return establishment means, and it does not.
Steps to reproduce the behavior
>>> from pyinaturalist import iNatClient
>>> client = iNatClient(default_params={'preferred_place_id': 6853})
>>> taxon = client.taxa(126575)
>>> taxon.establishment_means
>>> taxon = client.taxa(126575, preferred_place_id=6853)
>>> taxon.establishment_means
EstablishmentMeans(id=4560557, establishment_means='introduced', place=Place(id=6853, location=(0, 0), name='Nova Scotia'))
>>>
Workarounds
The steps to reproduce shown above also shows the workaround: pass the preferred place on the client.taxa()
call instead.
Environment
- OS & version: Debian 10
- Python version: 3.9
- Pyinaturalist version or branch: main
Okay, I found the problem. iNatClient
detects which of its default_params
would be valid for a given request by inspecting function signatures. It looks like the request method used here (pyinaturalist.v1.taxa.get_taxa_by_id()
) has an incomplete function signature.
Oh wait, that's probably because the iNat API docs don't list any request parameters for that endpoint: https://api.inaturalist.org/v1/docs/#!/Taxa/get_taxa_id
But I can see that it does respond to the preferred_place_id
param (as in your example): https://api.inaturalist.org/v1/taxa/126575?preferred_place_id=6853
So I guess I just wasn't aware that was possible. @synrg Do you happen to know what other (undocumented) request parameters work with that endpoint? For now I'm just going to add locale
, preferred_place_id
, and all_names
.
Fixes are in main. Your example now works as expected:
>>> from pyinaturalist import iNatClient
>>> client = iNatClient(default_params={'preferred_place_id': 6853})
>>> taxon = client.taxa(126575)
>>> taxon.establishment_means
EstablishmentMeans(
id=4560557,
establishment_means='introduced',
place=Place(id=6853, location=(0, 0), name='Nova Scotia')
)