question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

REVERT opportunity with CBV in django-reversion app?

See original GitHub issue

I use next CBV to revert to a specific version of a record. Unfortunately it raise error. I am little bit confused. Can you say whats the reason? Problem in my CBV or in django-reversion?

views.py:

from reversion.views import RevisionMixin
from django.views import View
from django.shortcuts import get_object_or_404, redirect
from reversion.models import Version
import reversion

class ArticleRevert(RevisionMixin, View):
    def get(self, request, *args, **kwargs):
        article=get_object_or_404(Article, pk=self.kwargs.get('pk'))
        revision=get_object_or_404(Version.objects.get_for_object(article), pk=self.kwargs.get('article_reversion_id')).revision
        reversion.set_comment("Revert to version #{}".format(revision.id))
        revision.revert()
        return redirect('article_list')

ERROR:

Traceback (most recent call last):
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/views.py", line 43, in do_revision_view
    return func(request, *args, **kwargs)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/Applications/Projects/web/project/article/views.py", line 165, in get
    reversion.set_comment("Revert to version #{}".format(reversion.id))
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/revisions.py", line 122, in set_comment
    _update_frame(comment=comment)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/revisions.py", line 87, in _update_frame
    _local.stack = _local.stack[:-1] + (_current_frame()._replace(**kwargs),)
  File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/revisions.py", line 53, in _current_frame
    raise RevisionManagementError("There is no active revision for this thread")
RevisionManagementError: There is no active revision for this thread

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
etianencommented, Dec 7, 2017

It’s not dirty, it’s exactly the was django’s transaction.atomic() is supposed to be used.

HOWEVER, I didn’t notice that you were using RevisionMixin! So that requires some more explanation.

RevisionMixin only does not create a revision for GET, HEAD or OPTIONS request methods, since those are supposed to be “safe”, and not modify data. You can get around this by using the reversion.create_revision() decorator manually, or by using a more appropriate HTTP method.

On 7 December 2017 at 03:26, NogerbekNurzhan notifications@github.com wrote:

It works now but it seems to me that its dirty solution.

Before I thought that @reversion.create_revision() we can use only in Function Based View and in Class Based View we need to use only RevisionMixin. Isn’t that right?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/etianen/django-reversion/issues/687#issuecomment-349851802, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJFCJFC8vIfkgoq8hDurbo8cj-FANJ0ks5s91rkgaJpZM4Q16Y1 .

0reactions
nurzhannogerbekcommented, Dec 7, 2017

It works now but it seems to me that its dirty solution.

Before I thought that @reversion.create_revision() we can use only in Function Based View and in Class Based View we need to use only RevisionMixin. Isn’t that right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How create REVERT opportunity in django-reversion app?
I have task to rewrite correct Function Based View to Class Based View . Below you can see my code. My question is...
Read more >
django-reversion API - Read the Docs
Use the django-reversion API to build version-controlled apps. ... Revert the first revision. versions[1].revision.revert() # Check the model instance has ...
Read more >
How create REVERT opportunity in django-reversion app
I have task to rewrite correct Function anycodings_django-reversion Based View to Class Based View. Below you anycodings_django-reversion can see my code.
Read more >
Xadmin: Drop-in Replacement Of Django Admin - Morioh
Drop-in replacement of Django admin comes with lots of goodies, ... and even how to change the look of your app and page...
Read more >
Two Scoops of Django: Best Practices for Django 1.8
What to Name Your Django Apps . . ... Allows for More App and Template Reverse Tricks . ... Constraining Django CBV/GCBV Access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found