London | 25-SDC-Nov | Jesus del Moral | Sprint 1 | Implement unfollow feature#188
London | 25-SDC-Nov | Jesus del Moral | Sprint 1 | Implement unfollow feature#188delmorallopez wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
illicitonion
left a comment
There was a problem hiding this comment.
Generally looks good, two small questions!
| if follow_user is None: | ||
| return |
There was a problem hiding this comment.
Doing nothing if the user doesn't exist kind of works, but also kind of doesn't.
On the plus side, the request didn't make sense, so we didn't do anything wrong.
On the down side, maybe the user actually wanted to follow someone new, and by ignoring their request, we haven't told them they probably made a mistake in their request.
How do you think is the best way to handle this?
There was a problem hiding this comment.
@illicitonion
I’ve updated the code to raise an error when the user does not exist, instead of silently returning. This makes the behaviour explicit and allows the caller to handle it appropriately.
The unfollow action remains idempotent when the relationship doesn’t exist
| ) | ||
|
|
||
|
|
||
| def unfollow(*, follower: User, follow_username: str): |
There was a problem hiding this comment.
It seems strange that you would have two different copies of this same code in different functions - why do you?
There was a problem hiding this comment.
@illicitonion
I was duplicating the user lookup logic inside the SQL query. I’ve refactored unfollow to reuse get_user() so the behaviour is consistent and easier to maintain.
This PR implements the ability for users to unfollow other users, improving control over their timeline and social graph