Why postgresql_query query_result contains empty dict on empty result?

Good day everyone. Wanted to understand rationale behind the decision to return empty dict when query returns no result. Looking through the code I see that this is intentional and explicit (community.postgresql/plugins/modules/postgresql_query.py at f3789b7c7c427f39a01dcc157810c4d835f24cee · ansible-collections/community.postgresql · GitHub). But documentation states that query_result is a list of dict objects, so imo this behavior contradicts with what is said in the doc.

Also it seems that one of the latest ansible core updates are now failing loops when empty dict is passed instead of list.

Maybe the doc can be updated to reflect this.

1 Like

@betalb hello, sorry for the late reply and thanks for bringing this up!
it was introduced here Psycopg 3 support (#517) · ansible-collections/community.postgresql@340a8bd · GitHub
i don’t know why exactly. That PR was related to introducing psycopg 3 support.
I’ve no idea if it’s directly related anyhow.
As I don’t see the PR author here on the forum, would you like to create an issue in the repo referring to this diff and ask him why it’s done that way?