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

revert: display information about IntegrityError #750

Closed
blueyed opened this issue Sep 4, 2018 · 5 comments · Fixed by #921
Closed

revert: display information about IntegrityError #750

blueyed opened this issue Sep 4, 2018 · 5 comments · Fixed by #921

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 4, 2018

It would be good to have the information about the IntegrityError in the error
message, instead of the generic "missing dependency":

> …/Vcs/django-reversion/reversion/models.py(32)

  24     def _safe_revert(versions):                                                                                                                                                          
  25         unreverted_versions = []                                                                                                                                                         
  26         __import__('pdb').set_trace()                                                                                                                                                    
  27         for version in versions:                                                                                                                                                         
  28             try:                                                                                                                                                                         
  29                 with transaction.atomic(using=version.db):                                                                                                                               
  30                     version.revert()                                                                                                                                                     
  31             except (IntegrityError, ObjectDoesNotExist):                                                                                                                                 
  32  ->             unreverted_versions.append(version)                                                                                                                                      
  33         if len(unreverted_versions) == len(versions):                                                                                                                                    
  34             raise RevertError(ugettext("Could not save %(object_repr)s version - missing dependency.") % {                                                                               
  35                 "object_repr": unreverted_versions[0],                                                                                                                                   
  36             })                                                                                                                                                                           
  37         if unreverted_versions:                                                                                                                                                          
  38             _safe_revert(unreverted_versions)                                                                                                                                            
 IntegrityError: duplicate key value violates unique constraint "app_subscriptionplan_organization_id_66f20bda_uniq"
DETAIL:  Key (organization_id, name)=(77, WEEKLY) already exists.
@etianen
Copy link
Owner

etianen commented Sep 5, 2018 via email

@blueyed
Copy link
Contributor Author

blueyed commented Sep 5, 2018

Isn't it (typically) a staff user, and therefore more OK?
I've thought like having this in some extra ("Details: %s") information.
Logging however would be better already of course.

@blueyed
Copy link
Contributor Author

blueyed commented Sep 5, 2018

Maybe it could be logged in general (logger.exception), and attached/wrapped into the RevertError to be displayed in the admin only?

To be clear: I am only talking about the "if len(unreverted_versions) == len(versions)" case.

@etianen
Copy link
Owner

etianen commented Sep 5, 2018 via email

tony added a commit to tony/django-reversion that referenced this issue Sep 21, 2022
This will be helpful @reversion.register users that explicitly declare
their fields.

Fixes etianen#750
tony added a commit to tony/django-reversion that referenced this issue Sep 21, 2022
This will be helpful @reversion.register users that explicitly declare
their fields.

Fixes etianen#750
@tony
Copy link
Contributor

tony commented Sep 21, 2022

@blueyed @etianen

I've followed up with a PR to this in #921

This was some time ago, but I've bumped into this a couple of times over the years - and always had to omit fields and just save everything.

Adding a logging.exception() to the IntegrityError instantly diagnosed this in my case.

tony added a commit to tony/django-reversion that referenced this issue Sep 25, 2022
This will be helpful @reversion.register users that explicitly declare
their fields.

Fixes etianen#750
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 a pull request may close this issue.

3 participants