Skip to content

Conversation

@27medkamal
Copy link

@27medkamal 27medkamal commented Oct 29, 2017

Sometimes, Django raises a DatabaseError instead of an IntegrityError when duplicates are found.

Reference here

@iceone
Copy link
Member

iceone commented Oct 30, 2017

Hi! Thanks for your PR!
But could you give more details of your use case?
When it raises such exception?

@27medkamal
Copy link
Author

27medkamal commented Oct 30, 2017

I did some debugging and that seems to happen when update_fields is used which is used in the save method by django-mptt
In a simple use case, an IntegrityError is raised but in more complex scenarios a DatabaseError seems to be raised instead.

@valignatev
Copy link

I guess that it theoretically could pass update_fields while creating new model instance somewhere in the tree: https://github.com/django-mptt/django-mptt/blob/85ff21fb93b61071dcb4cdc4bfc25e886f9ad486/mptt/models.py#L982

@iceone
Copy link
Member

iceone commented Nov 3, 2017

The main problem I see -- in your case when DatabaseError is raised there is no additional information passed to it. So we can't determine what field caused unique constraint violation to perform another try to regenerate UID.
And therefore in most cases DatabaseError will mean any error not related with UIDField.

Anyway, we need more detailed use case description to make appropriate fix (how to reproduce this bug).

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

Successfully merging this pull request may close these issues.

3 participants