The issue in the server component is that it does not know what the result 
is, since the queries are coming from the client and just being forwarded 
to bean-query.
Anyway, I'm now iterating over the results and converting sets 
(Inventories) into lists, which seems to do the job for now.
Thank you for the tip.

On Monday, 26 May 2025 at 8:36:18 am UTC+2 Alen Šiljak wrote:

>
> https://github.com/alensiljak/cashier-server-python/blob/b88eeedfe6429f888444b03afe75820361df402d/main.py#L96
>
> FastAPI is just a server. It automatically converts the output to JSON. 
> The queries are sent from the client. Technically, it could iterate over 
> the result and replace Inventories with a tuple or something like that. 
> Even just a string would work because it gets parsed back into objects 
> inside Cashier.
> Was just wondering if there is a better way or if something could be added 
> to make the serialization easier.
>
> On Monday, 26 May 2025 at 3:38:26 am UTC+2 [email protected] wrote:
>
>> I'm not sure where FastAPI comes into this story.
>> If you're querying using Python code you're getting Python objects which, 
>> with a little bit of data wrangling you should be able to convert to JSON.
>>
>>
>> On Sun, May 25, 2025 at 7:05 PM 'Alen Šiljak' via Beancount <
>> [email protected]> wrote:
>>
>>> Hi! I have a simple API that runs a bean-query
>>> ```
>>> select account, convert(value(sum(position)), 'EUR') as value
>>> ```
>>> to get all current balances in the same currency. Then the result is 
>>> serialized by FastAPI. Or at least it tries to.
>>> Unfortunately, it fails to serialize Inventories with 
>>> ```
>>> TypeError: unhashable type: 'list'
>>> ```
>>> Is there a way to get something serializable - a simple string, or a 
>>> number/string combination for the amounts - from the output of convert() 
>>> function?
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Beancount" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To view this discussion visit 
>>> https://groups.google.com/d/msgid/beancount/7844ca48-d018-4967-90ea-8016d9bf5c49n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/beancount/7844ca48-d018-4967-90ea-8016d9bf5c49n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/beancount/aba39c30-d1e2-4c2b-b166-de9fa318ea10n%40googlegroups.com.

Reply via email to