Fix logging KeyErrors in before_search