Shall we use ObjectID or string id? #156

Open
nagyv opened this Issue Nov 14, 2012 · 4 comments

Comments

Projects
None yet
2 participants

nagyv commented Nov 14, 2012

I've started to fix mongodb-engine to get it working with recent versions of toolbox. After blindly fixing the compiler, I've decided to have a look at the pre-existing test cases.

Quite a few of them were failing due to the fact that the returned obj.pk is a unicode string, instead of an ObjectID. As a result, I could make many failing tests pass by the following assertions:

class AssertionsMixin(object):

    def assertEqualModels(self, model1, model2, message=None):
        self.assertEqual(model1.pk, ObjectId(model2.pk), message)

    def assertEqualModelsList(self, model1, model2, message=None):
        model1_pks = map(attrgetter('pk'), model1)
        model2_pks = map(ObjectId, map(attrgetter('pk'), model2))
        model1_pks.sort()
        model2_pks.sort()
        self.assertEqualLists(model1_pks, model2_pks)

Is there any reason to prefer ObjectID or plain strings above the other? The test in lookup.py:115 fails, because it returns ObjectID keys in the resulting dictionary.

It might be easier to stick with ObjectID instead of unicode ids. What do you think? Is there any prior knowledge on this topic?

Contributor

jonashaag commented Nov 14, 2012

lookup.py? Where did you find that file?

btw, all three branches (1.3, 1.4, 1.5) of MongoDB Engine should work with the matching djangotoolbox versions.

nagyv commented Nov 14, 2012

sorry, it was the lookup module under the tests package

my version is here, it was forked today from master, and run against a virtualenv containing the master of djangotoolbox

https://github.com/nagyv/mongodb-engine/blob/fixing_tests_and_djangotoolbox/tests/lookup/tests.py

nagyv commented Nov 15, 2012

err, I've checked djangotoolbox versions again, but could not find any

I would be glad if you could help me in finding the matching branches though

these are my guesses:

django compatibility django-nonrel djangotoolbox mongodb-engine
1.3 master ? master
1.4 master of nonrel 1.4 features/django-1.4 1.4
1.5 master of nonrel 1.5 1.5 1.5

Am I right with the above table? What branch should I use for django-nonrel 1.3?

As I've heard that the 1.3 branches are the most stable, I would prefer to have that installed first, and would try to fix the 1.4 branch - if necessary - afterwards.

Contributor

jonashaag commented Nov 15, 2012

Follow these instructions for 1.3 http://django-mongodb.org/topics/setup.html

Or, if you want to have the latest 1.3.X minor release, go with master/master/master for django/toolbox/mongodb-engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment