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

Make PK also support uuid type #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhangcheng
Copy link

No description provided.

document = self.collection.find_one({'_id': ObjectId(self.kwargs['pk'])})
try:
pk = ObjectId(self.kwargs['pk'])
except:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the specific exception that is raised?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to convert pk into an ObjectId. PyMongo will do it for us. Quoted from "find_one" api description -

"Changed in version 1.7: Accept any type other than a dict instance as an "_id" query, not just ObjectId instances."

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, my bad! Actually PyMongo doesn't do it - Must have the right type to query.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flisky It doesn't work this way.

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.

None yet

3 participants