it has 40 comments total, but the problem is that when I request comments without specifying max_depth, and sort ordered by New, I receive only 10 comments, if I try to specify page, or limit, I get an error {"error":"couldnt_get_comments"}.
What values are you sending for limit and page? Are you sure they just aren't out of range?
without specifying max_depth
I think max_depth has a default, but I don't recall at the moment. Are the 10 comments you do get all trunk level comments, directly on the post?
My intention is doing something similar to an user pressing “Comments” on front of a community, like calling the community URL
From what I understand, depth only comes into play when you are viewing the comments of a specific post. If you are just listing comments across multiple posts in a community... they are presented flat. At least that is how lemmy-ui does it when I view comments for a community... which I assuming is using API /comment/list. Am I following what you are attempting?
Bug has been open for weeks. Doesn't seem to be a priority to undo the added HTML sanitation problems.
The code I pasted here on Lemmy is also on GitHub comment without being munged: https://github.com/LemmyNet/lemmy/pull/3865#issuecomment-1683324467
It's still mostly like the original function it is copied from, just some of the logic has been successfully stripped out. But it's probably worth looking at the bigger picture of just how much of the Rust conditional logic goes into building this SQL statement.