Collections sessions update_one $set upsert true error with none type object gett

This has been asked last year but no response given. My login_user(email, jwt) update_one won’t process with upsert. It seems most likely in the case of searching the sessions document for an email account (user_id) that hasn’t been logged before.

This is the error:
@pytest.mark.user_management
def test_login(client):
result = login_user(test_user.get(‘email’), test_user.get(‘jwt’))
assert result == {‘success’: True}
session_result = get_user_session(test_user.get(‘email’))

  assert session_result.get('user_id') == test_user.get('email')

E AttributeError: ‘NoneType’ object has no attribute ‘get’

This is the code I’ve tried in various permutations.
# TODO: User Management
# Use an UPSERT statement to update the “jwt” field in the document,
# matching the “user_id” field with the email passed to this function.
#update_doc={“user_id”: email, “jwt”: jwt}
#db.sessions.update_one({“user_id”: email}, {"$set":update_doc},upsert=True)
db.sessions.update_one({“user_id”: email}, {"$set":{“jwt”: jwt}},upsert=True)

db.sessions.update_one({“some_field”: “some_value”}, {"$set": {“some_other_field”: “some_other_value”}})

upsert_result=db.sessions.update_one({“user_id”: email}, {"$set": update_doc}, upsert=True)

    return {"success": True}
except Exception as e:
    return {"error": e}