macxred / cashctrl_api

Python client for the CashCtrl REST API
MIT License
0 stars 0 forks source link

Cache Returns Erroneous Values For Differing Parameters #41

Open lasuk opened 1 month ago

lasuk commented 1 month ago

Problem

Our current caching functionality is misleading in certain situations, for example when the default accounting year is changed between two calls.

  1. invoke list_ledger_entries() returns ledger entries of the current default accounting year and caches the return value.
  2. Change default accounting year, e.g:
    fiscal_periods = pd.DataFrame(api.get("fiscalperiod/list.json")['data'])
    api.post("fiscalperiod/switch.json", params={'id': fiscal_periods.query("name == '2022'")['id'].item()})
  3. When invoking list_ledger_entries() again, we would expect ledger entries of the 2022 accounting year but receive cached ledger entries of the previous call instead.

Proposed Solution

  1. CaschedApiClient needs to save a cached copy for every parameter set called.
  2. Default values need to be made explicit before calling the cached method.
  3. To this end, it would. probably be helpful to implement a (cached) list_fiscal_periods method.