Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pymongo version upgrade changes #5970

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions redash/query_runner/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from bson.timestamp import Timestamp
from bson.decimal128 import Decimal128
from bson.son import SON
from bson.json_util import object_hook as bson_object_hook
from bson.json_util import object_hook as bson_object_hook, JSONOptions

enabled = True

Expand Down Expand Up @@ -67,7 +67,8 @@ def datetime_parser(dct):
if "$oids" in dct:
return parse_oids(dct["$oids"])

return bson_object_hook(dct)
opts = JSONOptions(tz_aware=True)
return bson_object_hook(dct, json_options=opts)


def parse_query_json(query):
Expand Down Expand Up @@ -244,7 +245,7 @@ def _get_collection_fields(self, db, collection_name):
def get_schema(self, get_stats=False):
schema = {}
db = self._get_db()
for collection_name in db.collection_names():
for collection_name in db.list_collection_names():
if collection_name.startswith("system."):
continue
columns = self._get_collection_fields(db, collection_name)
Expand Down Expand Up @@ -301,19 +302,20 @@ def run_query(self, query, user):

cursor = None
if q or (not q and not aggregate):
if s:
cursor = db[collection].find(q, f).sort(s)
if "count" in query_data:
Mukesh-R marked this conversation as resolved.
Show resolved Hide resolved
options = {opt: query_data[opt] for opt in ("skip", "limit") if opt in query_data}
cursor = db[collection].count_documents(q, **options)
else:
cursor = db[collection].find(q, f)

if "skip" in query_data:
cursor = cursor.skip(query_data["skip"])
if s:
cursor = db[collection].find(q, f).sort(s)
else:
cursor = db[collection].find(q, f)

if "limit" in query_data:
cursor = cursor.limit(query_data["limit"])
if "skip" in query_data:
cursor = cursor.skip(query_data["skip"])

if "count" in query_data:
cursor = cursor.count()
if "limit" in query_data:
cursor = cursor.limit(query_data["limit"])

elif aggregate:
allow_disk_use = query_data.get("allowDiskUse", False)
Expand Down
2 changes: 1 addition & 1 deletion requirements_all_ds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ influxdb==5.2.3
mysqlclient==2.1.1
oauth2client==4.1.3
pyhive==0.6.1
pymongo[tls,srv]==3.9.0
pymongo[tls,srv]==4.3.3
vertica-python==0.9.5
td-client==1.0.0
pymssql==2.1.5
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mock==3.0.5

# PyMongo and Athena dependencies are needed for some of the unit tests:
# (this is not perfect and we should resolve this in a different way)
pymongo[srv,tls]==3.9.0
pymongo[srv,tls]==4.3.3
boto3>=1.10.0,<1.11.0
botocore>=1.13,<1.14.0
PyAthena>=1.5.0,<=1.11.5
Expand Down