nit: In Python, it is idiomatic to compare with `None` using `is` (`if user_id is None:`), since `None` is a singleton and a reference compare is faster.