Skip to content

Conversation

cben
Copy link

@cben cben commented Feb 20, 2024

With current pymongo==3.13.0, was causing exception:

> podman-compose exec web env PYTHONPATH=. python explainshell/manager.py --log info --verify
...
INFO:explainshell.store:creating store, db = 'explainshell', host = 'mongodb://db'
Traceback (most recent call last):
  File "explainshell/manager.py", line 201, in <module>
    sys.exit(main(args.files, args.db, args.host, args.overwrite, args.drop, args.verify))
  File "explainshell/manager.py", line 165, in main
    ok = s.verify()
  File "/opt/webapp/explainshell/store.py", line 372, in verify
    manpages = set([m['_id'] for m in self.manpage.find(fields={'_id':1})])
  File "/usr/local/lib/python2.7/site-packages/pymongo/collection.py", line 1696, in find
    return Cursor(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'fields'
exit code: 1

Now works:

> podman-compose exec web env PYTHONPATH=. python explainshell/manager.py --log info --verify
...
INFO:explainshell.store:creating store, db = 'explainshell', host = 'mongodb://db'
exit code: 0

I tested the other calls too; updatemanpage unreachable from
current CLI but tested same call in another code path.

Not sure when pymongo API changed; oldest doc I found online https://pymongo.readthedocs.io/en/3.5.1/api/pymongo/collection.html#pymongo.collection.Collection.find which doesn't mention fields= only projection=. Probably broken since 8406b31?

Change from {x: 1} to ['x'] style is cosmetic, reads less magic to me, but projection arg supports both.

With current pymongo==3.13.0, was causing exception:
    TypeError: __init__() got an unexpected keyword argument 'fields'

Not sure when pymongo API changed; oldest doc I found online
https://pymongo.readthedocs.io/en/3.5.1/api/pymongo/collection.html#pymongo.collection.Collection.find
which doesn't mention `fields=` only `projection=`.

Change from {x: 1} to ['x'] style is cosmetic, reads less magic to me,
but `projection` arg supports both.
@idank
Copy link
Owner

idank commented Feb 21, 2024

Thanks! Shouldn't the dependency be updated as well?

@cben
Copy link
Author

cben commented Feb 26, 2024

This updates the code to match documented functionality for pymongo==3.13.0 currently in requirements.txt.

The dependency has already been bumped in commit 8406b31 and I'm pretty convinced these code paths have been broken since :-D

Oh yes here it is in the docs:

Changed in version 3.0: Changed the parameter names spec, fields, timeout, and partial to filter, projection, no_cursor_timeout, and allow_partial_results respectively. ...

Also here in pymongo 2->3 migration guide: https://pymongo.readthedocs.io/en/3.12.1/migrate-to-pymongo3.html#fields-renamed-projection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants