omarryhan/aiogoogle

Inconsistent response.

Closed this issue · 5 comments

Hello,

Thanks a lot for your work with support of this library, very much appreciated!

I'm run into issue with:

results[0] if isinstance(results, list) and len(results) == 1 else results

In simple words it return Dict or List[Dict] depending on number of entries in the response.
This behavior is not obvious for clients.

Could you please provide a historical background for this?
Would you accept change to always return List object to the client? Is there any implications for this?

Thanks

Hey, my pleasure!

The reason why the return type is as such is because when sending a request you can send only 1 request which will only return 1 response, or you can send multiple requests in parallel e.g.

await aiogoogle.as_user(
    req1,
    req2
)

Which will return a list of 2 responses.

Is this causing you type errors? I wrote this lib before Python type hints were introduced to the language, so I couldn't have foreseen this problem happening unfortunately.

Yes, exactly.

When we issues request with one entry - we get Dict[Any, Any]
if we sending two and more - we get List[Dict[Any,Any]]
Note: we are using aiogoogle.as_service_account call.

This behavior leads to an extra W.As on client’s side to make it possible process data properly due to typing issues.

So, I’m curious if we can always return a list? Even, if there’s no (empty) response to return an empty list?

Pros:

  • It’s will simplify current logic.
  • Make behavior more deterministic.
  • Clients will have more control over processing / typing.

Thanks

That's a lot cleaner. However, a huge downside is that it would be a backward incompatible change, which I'm trying to avoid as best I can.

I'm open to adding a kwarg that enables this behavior but the type signature will unfortunately have to stay the same.

Sorry for the inconvenience @artemkostin
feel free to reopen the issue if you have further questions, thanks 🙏

@omarryhan, sorry for a late reply and thanks a lot for your prompt response.
I think it's fine to close this issue. Since I'm on the same page with you now!
Thanks one more time for your effort!