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

unique_with not enforced #205

Closed
jason-w opened this issue Jan 1, 2013 · 9 comments
Closed

unique_with not enforced #205

jason-w opened this issue Jan 1, 2013 · 9 comments

Comments

@jason-w
Copy link

jason-w commented Jan 1, 2013

I'm able to create multiple documents with the same values in the fields I've defined using unique_with. I'm using mongoengine in conjunction with flask-mongoengine in my flask app.

Here's my document definition:

class Item (db.Document):

    owner_id = db.ObjectIdField(required=True)
    owner_item_id = db.StringField(required=True, unique_with = 'owner_id')

Using the above document definition, I'm able to create multiple Items using the same owner_id and owner_item_id combination. The only time the NotUniqueError exception is thrown is the first time time I insert a duplicate document after I restart my local flask app. Every time after that, I can create as many duplicate documents as I wish.

Versions:
flask-mongoengine==0.6
mongoengine==0.7.8

UPDATE: This happens after I deleted the Item collection and on subsequent creates.

@andrew-azarov
Copy link

The same problem...
With the delete it's a big problem, during cloning no enforcement done on the indexes and then on delete all of the pages got deleted...

@rozza
Copy link
Contributor

rozza commented Jan 7, 2013

Please log this in flask-mongoengine - seems like a setup bug.

Are the indexes created correctly in mongodb? Does it actually save
duplicate documents?

On Mon, Jan 7, 2013 at 5:29 PM, Equand notifications@github.com wrote:

The same problem...
With the delete it's a big problem, during cloning no enforcement done on
the indexes and then on delete all of the pages got deleted...


Reply to this email directly or view it on GitHubhttps://github.com//issues/205#issuecomment-11961274.

@andrew-azarov
Copy link

I don't have flask-mongoengine though.
I use bottlepy with mongoengine, my own written plugin.

@andrew-azarov
Copy link

somehow changing the date field to complexdatetimefield made it work...

@rozza
Copy link
Contributor

rozza commented Jan 8, 2013

Hmm troubling - Equand can you provide more information or a test case?
I'm not sure what the core issue is.

Also, is your plugin published? Available via pypi? I should make sure I
add it to the homepage!

Thanks,

Ross

On Tue, Jan 8, 2013 at 12:32 AM, Equand notifications@github.com wrote:

somehow changing the date field to complexdatetimefield made it work...


Reply to this email directly or view it on GitHubhttps://github.com//issues/205#issuecomment-11979218.

@andrew-azarov
Copy link

The core issue was with DateTimeField and datetime.datetime.now() realization and differences from python and javascript...
ms in js are corrupted (resolution is lower than default OS/python). So when selecting from collection with query on the DateTimeField (as it was the primary_key field) I received all of the resources (and successfully deleted them).
Or I think this was the main problem... I'm still not 100% sure what caused such behavior.

regarding plugin
There's no difference to sqlite plugin of bottlepy
it just adds connect(db,alias,**kwargs) in the beginning and db.end_request() at the end
The plugin is in the end of hmarr#272

@abulte
Copy link

abulte commented Apr 10, 2013

I have the exact same problem as @jason-w. Not DateTimeField in my setup.

The duplicate documents are actually created in MongoDB.

@rozza
Copy link
Contributor

rozza commented Apr 11, 2013

Hmm this is confusing then - is there an unique index in mongodb?

@bagerard
Copy link
Collaborator

bagerard commented Oct 7, 2018

@erdenezul Issue is quite old and it looks like it was due to some confusion between python/js rather than a bug in mongoengine. I had a look at unique_with and it looks fine, index gets created properly in mongodb. Maybe we should close this issue.

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

No branches or pull requests

6 participants