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

Duplicate connections #5

Closed
mbartz opened this issue May 3, 2012 · 2 comments
Closed

Duplicate connections #5

mbartz opened this issue May 3, 2012 · 2 comments

Comments

@mbartz
Copy link

mbartz commented May 3, 2012

We have found rare instances of duplicated connections in the relatedobject table.

The scenario in which we are using generic M2M is to keep a list of attached Reference Values on an XML object. We iterate through the list and attach the Reference Value objects to the original XML object. In the rare cases where the duplication has occurred, the date created field of the table shows that they were created approximately 2 seconds apart from each other.

The error occurs when we attempt another processing run of the XML object. When we attempt the connection the "second" time, the get_or_create in the connection model fails to catch the MultipleObjectsReturned error.

We cannot reliably reproduce the problem. In our database we have approximately 700k connections and have only had about a dozen errors.

We are now trapping the errors and have considered adding a unique together on the related object table.

Sorry I don't have a reproducible scenario.

@coleifer
Copy link
Owner

coleifer commented May 3, 2012

Thanks for the note, I'd be happy to look into this. So the get_or_create() isn't behaving correctly?

@mbartz
Copy link
Author

mbartz commented May 3, 2012

In the get_or_create of the RelatedManager:

            kwargs.update(core_filters)
            return super(RelatedManager, self).get_or_create(**kwargs)

in the base get_or_create it only handles the ObjectDoesNotExist exception.

I think the implicit assumption is that the 4-tuple can only exist once.

I think the easiest thing to do is to add a unique_together(parent_id, parent_type, object_type, object_id).

I know it's redundant but it would fix the problem. If we see any patterns, I repost the data.

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

2 participants