fix datetime callable, and catch keyerror on middleware