I am trying to create a function that automatically deletes OTP that are expired in FastAPI. I tried this: @app.on_event('startup') @repeat_every(seconds=300) async def delete_expired_otp(db: db_dependency): print("deleting") expired_otp = db.query(OTPModel).filter(OTPModel.expires_at < datetime.utcnow()).all() if expired_otp: for otp in expired_otp: db.delete(otp) db.commit() print("deleted") I even changed the filter to be is_used to be true, but that didn't change anything. Continue reading...