<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def search_profiles(db, no_gender=False):
 """List unique identities profiles. The function will return the list of profiles filtered by the given parameters. When `no_gender` is set, only profiles without gender values will be returned. :param db: database manager :param no_gender: return only those profiles without gender :returns: a list of profile entities """

    profiles = []

    with db.connect() as session:
        query = session.query(Profile)

        if no_gender:
            query = query.filter(Profile.gender == None)

        profiles = query.order_by(Profile.uuid).all()

        # Detach objects from the session
        session.expunge_all()

    return profiles