Skip to content

Error when using unique_with and inheritance #629

Open
@latteier

Description

@latteier

When upgrading to mongo 2.6 I get this error (which I don't get under mongo 2.4).

Trying to save an instance of my document (SubclassDoc):

  File "/Users/amos/Work/rfb-dev/eggs/mongoengine-0.8.7-py2.7.egg/mongoengine/document.py", line 294, in save
    raise OperationError(message % unicode(err))
OperationError: Could not save document (command SON([('createIndexes', u'feed'), ('indexes', [{'name': u'content_1_user_1', 'key': SON([('content', 1), ('user', 1)]), 'unique': True, 'background': False, 'sparse': True, 'dropDups': False}])]) failed: Index with name: content_1_user_1 already exists with different options)

I think the problem is that I have a base document class and a class that derives it that want to create different unique indexes on the same collection.

class FeedItem(Document):
    user = ReferenceField('User', required=True)
    content = ReferenceField('Content', required=True, unique_with='user')

class SubclassDoc(BaseDoc):
    pass
>>> BaseDoc._unique_with_indexes()
[{'fields': [('content', 1), ('user', 1)], 'unique': True, 'sparse': False}]
>>> SubclassDoc._unique_with_indexes()
[{'fields': [('content', 1), ('user', 1)], 'unique': True, 'sparse': True}]

I don't understand why this works on mongo 2.4 but not on mongo 2.6.

Thanks for any suggestions!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions