Note: running the SQL I have in my endpoint by hand only returns BYB-SL East as expected. However, there is no filtering done nor is the endpoint being called.
The custom query is being called, albeit not directly from the frontend. The function frappe.desk.search.search_link in turn calls a custom query whenever specified. You can add a print function to your query to test this.
There are quite a few instances where this is done on refresh instead of onload. I think set_query can be called anytime as long as you’re using the delivery_zone field after the set_query call. Are you maybe testing the field before this code gets triggered? Maybe try a console.log to see if this code gets triggered at all…
After further digging, I have found that while the query does not work when editing the field in the grid row, the query works fine in the larger, expanded view. Is there a way to fix it?
It also seems that the datepicker object for the Delivery Date fields are different between the row and this expanded view…currently investigating the difference.