Skip to content

Commit

Permalink
feat: upgrading pymongo.
Browse files Browse the repository at this point in the history
  • Loading branch information
awais786 authored and mumarkhan999 committed Jun 26, 2024
1 parent c32b68c commit 87a2d42
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 98 deletions.
2 changes: 1 addition & 1 deletion eventtracking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""A simple event tracking library"""

__version__ = '2.4.0'
__version__ = '2.4.1'
6 changes: 3 additions & 3 deletions eventtracking/backends/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def _create_indexes(self):
# TODO: The creation of indexes can be moved to a Django
# management command or equivalent. There is also an option to
# run the indexing on the background, without locking.
self.collection.ensure_index([('time', pymongo.DESCENDING)])
self.collection.ensure_index('name')
self.collection.create_index([('time', pymongo.DESCENDING)])
self.collection.create_index('name')

def send(self, event):
"""Insert the event in to the Mongo collection"""
try:
self.collection.insert(event, manipulate=False)
self.collection.insert_one(event)
except (PyMongoError, BSONError):
# The event will be lost in case of a connection error or any error
# that occurs when trying to insert the event into Mongo.
Expand Down
4 changes: 2 additions & 2 deletions eventtracking/backends/tests/test_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch
from unittest.mock import sentinel

import pymongo
from pymongo.errors import PyMongoError
from bson.errors import BSONError

Expand All @@ -28,8 +29,7 @@ def test_mongo_backend(self):
self.backend.send(events[1])

# Check if we inserted events into the database

calls = self.backend.collection.insert.mock_calls
calls = self.backend.collection.insert_one.mock_calls

self.assertEqual(len(calls), 2)

Expand Down
8 changes: 4 additions & 4 deletions eventtracking/backends/tests/test_mongodb_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ def test_sequential_events(self):

# Ensure MongoDB has finished writing out the events before we
# run our query.
self.mongo_backend.connection.fsync()
self.mongo_backend.connection.admin.command('fsync', lock=True)
collection = self.mongo_backend.collection
cursor = collection.find()
self.assertEqual(collection.count_documents({}), 10)

mem_events = {}
for event in self.memory_backend.events:
mem_events[event['data']['sequence']] = event
self.assertEqual(len(mem_events), 10)

cursor = self.mongo_backend.collection.find()
self.assertEqual(cursor.count(), 10)

for event in cursor:
mem_event = mem_events[event['data']['sequence']]
mem_event['_id'] = event['_id']
Expand Down
5 changes: 3 additions & 2 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
-c constraints.txt

django
pymongo>=2.7.2,<4.0.0
# https://pymongo.readthedocs.io/en/4.4.0/migrate-to-pymongo4.html#son-items-now-returns-dict-items-object
pymongo>=4.0.0,<4.4.1
pytz
six
celery
celery<5.4.0
edx-django-utils
openedx-events>=9.5.1
edx-toggles
35 changes: 21 additions & 14 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ click-plugins==1.1.1
# via celery
click-repl==0.3.0
# via celery
code-annotations==1.7.0
code-annotations==1.8.0
# via edx-toggles
django==4.2.11
django==4.2.13
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/base.in
Expand All @@ -57,36 +57,42 @@ django-waffle==4.1.0
# via
# edx-django-utils
# edx-toggles
edx-django-utils==5.12.0
dnspython==2.6.1
# via pymongo
edx-ccx-keys==1.3.0
# via openedx-events
edx-django-utils==5.14.2
# via
# -r requirements/base.in
# edx-toggles
# openedx-events
edx-opaque-keys[django]==2.5.1
# via openedx-events
edx-opaque-keys[django]==2.10.0
# via
# edx-ccx-keys
# openedx-events
edx-toggles==5.2.0
# via -r requirements/base.in
fastavro==1.9.4
# via openedx-events
jinja2==3.1.3
jinja2==3.1.4
# via code-annotations
kombu==5.3.6
kombu==5.3.7
# via celery
markupsafe==2.1.5
# via jinja2
newrelic==9.8.0
newrelic==9.11.0
# via edx-django-utils
openedx-events==9.6.0
openedx-events==9.11.0
# via -r requirements/base.in
pbr==6.0.0
# via stevedore
prompt-toolkit==3.0.43
prompt-toolkit==3.0.47
# via click-repl
psutil==5.9.8
psutil==6.0.0
# via edx-django-utils
pycparser==2.22
# via cffi
pymongo==3.13.0
pymongo==4.4.0
# via
# -r requirements/base.in
# edx-opaque-keys
Expand All @@ -103,8 +109,9 @@ pyyaml==6.0.1
six==1.16.0
# via
# -r requirements/base.in
# edx-ccx-keys
# python-dateutil
sqlparse==0.4.4
sqlparse==0.5.0
# via django
stevedore==5.2.0
# via
Expand All @@ -113,7 +120,7 @@ stevedore==5.2.0
# edx-opaque-keys
text-unidecode==1.3
# via python-slugify
typing-extensions==4.10.0
typing-extensions==4.12.2
# via
# asgiref
# edx-opaque-keys
Expand Down
4 changes: 2 additions & 2 deletions requirements/celery53.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ celery==5.3.6
click==8.1.7
click-didyoumean==0.3.1
click-repl==0.3.0
kombu==5.3.6
prompt-toolkit==3.0.43
kombu==5.3.7
prompt-toolkit==3.0.47
vine==5.1.0
16 changes: 8 additions & 8 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ chardet==5.2.0
# via tox
colorama==0.4.6
# via tox
coverage==7.4.4
coverage==7.5.4
# via -r requirements/ci.in
distlib==0.3.8
# via virtualenv
filelock==3.13.3
filelock==3.15.4
# via
# tox
# virtualenv
packaging==24.0
packaging==24.1
# via
# pyproject-api
# tox
platformdirs==4.2.0
platformdirs==4.2.2
# via
# tox
# virtualenv
pluggy==1.4.0
pluggy==1.5.0
# via tox
pyproject-api==1.6.1
pyproject-api==1.7.1
# via tox
tomli==2.0.1
# via
# pyproject-api
# tox
tox==4.14.2
tox==4.15.1
# via -r requirements/ci.in
virtualenv==20.25.1
virtualenv==20.26.3
# via tox
Loading

0 comments on commit 87a2d42

Please sign in to comment.