I was having the same issue on a repeater field, not being able to patch it with @kokers ‘s solution.
This comment fixed it https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/#comment-33273. I don’t really get why but it might help someone !