MongoDB decode bson codec pymongo

Issue Summary

A summary of the issue and the browser/OS environment in which it occurs.

Technical details:

  • Redash Version: v10
  • Browser/OS: Google Chrome
  • How did you install Redash: Kubernetes with Helm Chart

I cannot load schema on few databases on mongodb with unknown unicode decode bson
im using pymongo > 3.90
maybe i need some unicode_decode_error_handler (CMIIW) or some custom query runner mongodb
can anyone having same issue?

im can connect to the DB anyway but cannot load its schema

error log on scheduler worker :

Traceback (most recent call last):
File “/app/redash/tasks/queries/”, line 171, in refresh_schema
File “/app/redash/models/”, line 198, in get_schema
schema = query_runner.get_schema(get_stats=refresh)
File “/app/redash/query_runner/”, line 244, in get_schema
columns = self._get_collection_fields(db, collection_name)
File “/app/redash/query_runner/”, line 228, in _get_collection_fields
for d in db[collection_name].find().sort([(“$natural”, 1)]).limit(1):
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1156, in next
if len(self.__data) or self._refresh():
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1073, in _refresh
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 955, in __send_message
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1346, in _run_operation_with_response
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1464, in _retryable_read
return func(session, server, sock_info, slave_ok)
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1340, in _cmd
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 131, in run_operation_with_response
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1030, in _unpack_response
File “/home/redash/.local/lib/python3.7/site-packages/pymongo/”, line 1591, in unpack_response
self.payload_document, codec_options, user_fields)
File “/home/redash/.local/lib/python3.7/site-packages/bson/”, line 1098, in _decode_all_selective
return decode_all(data, codec_options)
bson.errors.InvalidBSON: ‘utf-8’ codec can’t decode byte 0xd4 in position 1: invalid continuation byte


I googled your error and found the fix: python - pymongo error: bson.errors.InvalidBSON: 'utf8' codec can't decode byte 0xa1 in position 25: invalid start byte - Stack Overflow

This will need to be applied to the query runner. If the change works on your end, please open a pull request and we’ll merge it so that others can benefit also.