Queries to BigQuery fails because of "Invalid control character"

Technical details:

Datasource

  • GCP Bigquery

Error

Error running query: Invalid control character at: line 5112 column 51 (char 219516)

adhoc_worker_1      | [2019-11-21 04:26:35,436][PID:30][INFO][ForkPoolWorker-4] task_name=redash.tasks.execute_query task_id=42fd4064-1c80-460b-8eab-261782c92b0a task=execute_query state=executing_query query_hash=27b894982613359962161f20b5458770 type=bigquery ds_id=1  task_id=42fd4064-1c80-460b-8eab-261782c92b0a queue=queries query_id=adhoc username=hogefuga@example.com
adhoc_worker_1      | [2019-11-21 04:26:35,445][PID:30][WARNING][ForkPoolWorker-4] Unexpected error while running query:
adhoc_worker_1      | Traceback (most recent call last):
adhoc_worker_1      |   File "/app/redash/tasks/queries.py", line 361, in run
adhoc_worker_1      |     data, error = query_runner.run_query(annotated_query, self.user)
adhoc_worker_1      |   File "/app/redash/query_runner/big_query.py", line 294, in run_query
adhoc_worker_1      |     bigquery_service = self._get_bigquery_service()
adhoc_worker_1      |   File "/app/redash/query_runner/big_query.py", line 149, in _get_bigquery_service
adhoc_worker_1      |     return build("bigquery", "v2", http=http)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
adhoc_worker_1      |     return wrapped(*args, **kwargs)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 210, in build
adhoc_worker_1      |     credentials=credentials)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
adhoc_worker_1      |     return wrapped(*args, **kwargs)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 317, in build_from_document
adhoc_worker_1      |     service = json.loads(service)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/json/__init__.py", line 339, in loads
adhoc_worker_1      |     return _default_decoder.decode(s)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/json/decoder.py", line 364, in decode
adhoc_worker_1      |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
adhoc_worker_1      |   File "/usr/local/lib/python2.7/json/decoder.py", line 380, in raw_decode
adhoc_worker_1      |     obj, end = self.scan_once(s, idx)
adhoc_worker_1      | ValueError: Invalid control character at: line 5112 column 51 (char 219516)
adhoc_worker_1      | [2019-11-21 04:26:35,445][PID:30][INFO][ForkPoolWorker-4] task_name=redash.tasks.execute_query task_id=42fd4064-1c80-460b-8eab-261782c92b0a task=execute_query query_hash=27b894982613359962161f20b5458770 data_length=None error=[Invalid control character at: line 5112 column 51 (char 219516)]
adhoc_worker_1      | [2019-11-21 04:26:35,447][PID:30][ERROR][ForkPoolWorker-4] Task redash.tasks.execute_query[42fd4064-1c80-460b-8eab-261782c92b0a] raised unexpected: QueryExecutionError(u'Invalid control character at: line 5112 column 51 (char 219516)',)
adhoc_worker_1      | Traceback (most recent call last):
adhoc_worker_1      |   File "/usr/local/lib/python2.7/site-packages/celery/app/trace.py", line 385, in trace_task
adhoc_worker_1      |     R = retval = fun(*args, **kwargs)
adhoc_worker_1      |   File "/app/redash/worker.py", line 84, in __call__
adhoc_worker_1      |     return TaskBase.__call__(self, *args, **kwargs)
adhoc_worker_1      |   File "/usr/local/lib/python2.7/site-packages/celery/app/trace.py", line 648, in __protected_call__
adhoc_worker_1      |     return self.run(*args, **kwargs)
adhoc_worker_1      |   File "/app/redash/tasks/queries.py", line 436, in execute_query
adhoc_worker_1      |     scheduled_query).run()
adhoc_worker_1      |   File "/app/redash/tasks/queries.py", line 382, in run
adhoc_worker_1      |     raise result
adhoc_worker_1      | QueryExecutionError: Invalid control character at: line 5112 column 51 (char 219516)

Details

The bigquery query has failed in redash v8.0.0.
Although it was successful until yesterday, it started to fail today.
The query is correct because the query is successful with the GCP BigQuery console.
Also, because the query to AWS Athena does not fail, redash itself is fine.
On the other hand, redash v7.0.0(redash/redash:7.0.0.b18042) does not fail, so it is currently downgraded.

I think this is caused by an error in Python’s json.decoder. Is there a solution for this?