Summary
cursor.count() was removed in pymongo 4.0. The helper functions user_exist() and verify_user() in app.py call users.find({...}).count(), which raises AttributeError at runtime against a real MongoDB instance. The tests pass only because the cursor is fully mocked.
Background
The repo pins pymongo==4.7.2 (requirements.txt line 4), making this a latent runtime crash. Every registration and login request will fail when connected to an actual database, which fundamentally breaks the tutorial's purpose.
Affected Areas
web/app.py — user_exist() function (uses .count())
web/app.py — verify_user() function (uses .count())
web/tests/test_app.py — mock cursor sets cursor.count.return_value (must be updated)
Recommended Fix
# Before
def user_exist(username):
return users.find({"Username": username}).count() > 0
# After
def user_exist(username):
return users.count_documents({"Username": username}) > 0
Update test helpers to set mock_users.count_documents.return_value accordingly and remove the .count mock attribute.
Acceptance Criteria
Complexity Estimate
S — small code change but requires updating tests and verifying end-to-end.
Priority
High — causes an AttributeError crash on every register and login against a real database.
Auto-identified by workspace issue-logger
Category: dependency upgrade
Complexity: S
Repository: DewaldOosthuizen/python_rest_tutorial
Summary
cursor.count()was removed in pymongo 4.0. The helper functionsuser_exist()andverify_user()inapp.pycallusers.find({...}).count(), which raisesAttributeErrorat runtime against a real MongoDB instance. The tests pass only because the cursor is fully mocked.Background
The repo pins
pymongo==4.7.2(requirements.txt line 4), making this a latent runtime crash. Every registration and login request will fail when connected to an actual database, which fundamentally breaks the tutorial's purpose.Affected Areas
web/app.py—user_exist()function (uses.count())web/app.py—verify_user()function (uses.count())web/tests/test_app.py— mock cursor setscursor.count.return_value(must be updated)Recommended Fix
Update test helpers to set
mock_users.count_documents.return_valueaccordingly and remove the.countmock attribute.Acceptance Criteria
cursor.count()replaced withcount_documents()in all helperscount_documentsinstead of cursor.countComplexity Estimate
S — small code change but requires updating tests and verifying end-to-end.
Priority
High — causes an
AttributeErrorcrash on every register and login against a real database.Auto-identified by workspace issue-logger
Category: dependency upgrade
Complexity: S
Repository: DewaldOosthuizen/python_rest_tutorial