Inexplicable issue when using @app.server.route

I have come across an issue that I am struggling to debug. When using @app.server.route('/') to allow users to download a CSV from the Dash app, the download link will work, but sometimes will not execute the code in this decorator. How can I ensure that the code is always executed?

I have produced an MRE and explained in much more detail on StackOverflow

Thank you