Changes to django/db/models/fields/__init__.py broke ForeignKeys #8

Open
dgrinb01 opened this Issue Apr 11, 2012 · 3 comments

Projects

None yet

4 participants

@dgrinb01

For MongoDB, ALL ForeignKeys now are saved not as ObjectIds but as strings. This completely breaks pretty much any lookup that has ForeignKey fields. Please either revert back (this any any related change) or fix and and properly test it before making it available.

This is a show-stopper and not only breaks applications but also messes up data in the database.

@jonashaag
Contributor

Cannot reproduce. Maybe you mixed up branches.

    def test_djangononrel_issue_8(self):
        """
        ForeignKeys should be ObjectIds, not unicode.
        """
        from bson.objectid import ObjectId
        from query.models import Blog, Post

        post = Post.objects.create(blog=Blog.objects.create())
        collection = get_collection(Post)
        assert collection.count() == 1
        doc = collection.find_one()
        self.assertIsInstance(doc['blog_id'], ObjectId)
@jonashaag jonashaag added a commit to django-nonrel/mongodb-engine that referenced this issue May 14, 2012
@jonashaag jonashaag Added test for django-nonrel/django-nonrel#8 172e334
@malins
malins commented Jun 24, 2012

I'm using the 1.4 branch and have the same problem, foreign keys are saved as strings, which is not very nice. How to fix this?

@gpitfield
Member

I don't have this exact issue, but related I am finding that ForeignKeys in ListFields of Embedded Objects are being saved as strings. Is this a known issue/has it been fixed at some point?

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