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

Support asyncio views #904

Merged
merged 2 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
DJANGO_DATABASE_PASSWORD_MYSQL: root
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']
python-version: [3.7, 3.8, 3.9, '3.10']
django-version:
- '>=4.0a1,<4.1'
- '>=3.2,<4.0'
Expand All @@ -51,8 +51,6 @@ jobs:
- '>=2.1,<2.2'
- '>=2.0,<2.1'
exclude:
- python-version: 3.6
django-version: '>=4.0a1,<4.1'
- python-version: 3.7
django-version: '>=4.0a1,<4.1'
- python-version: '3.10'
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version control for model instances.
Requirements
============

- Python 3.6 or later
- Python 3.7 or later
- Django 2.0 or later

Features
Expand Down
23 changes: 9 additions & 14 deletions reversion/revisions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextvars import ContextVar
from collections import namedtuple, defaultdict
from contextlib import contextmanager
from functools import wraps
from threading import local
from django.apps import apps
from django.core import serializers
from django.core.exceptions import ObjectDoesNotExist
Expand Down Expand Up @@ -34,23 +34,17 @@
))


class _Local(local):

def __init__(self):
self.stack = ()


_local = _Local()
_stack = ContextVar("reversion-stack", default=[])


def is_active():
return bool(_local.stack)
return bool(_stack.get())


def _current_frame():
if not is_active():
raise RevisionManagementError("There is no active revision for this thread")
return _local.stack[-1]
return _stack.get()[-1]


def _copy_db_versions(db_versions):
Expand Down Expand Up @@ -79,16 +73,17 @@ def _push_frame(manage_manually, using):
db_versions={using: {}},
meta=(),
)
_local.stack += (stack_frame,)
_stack.set(_stack.get() + [stack_frame])


def _update_frame(**kwargs):
_local.stack = _local.stack[:-1] + (_current_frame()._replace(**kwargs),)
_stack.get()[-1] = _current_frame()._replace(**kwargs)


def _pop_frame():
prev_frame = _current_frame()
_local.stack = _local.stack[:-1]
stack = _stack.get()
del stack[-1]
if is_active():
current_frame = _current_frame()
db_versions = {
Expand Down Expand Up @@ -284,7 +279,7 @@ def _create_revision_context(manage_manually, using, atomic):
try:
yield
# Only save for a db if that's the last stack frame for that db.
if not any(using in frame.db_versions for frame in _local.stack[:-1]):
if not any(using in frame.db_versions for frame in _stack.get()[:-1]):
current_frame = _current_frame()
_save_revision(
versions=current_frame.db_versions[using].values(),
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ def read(filepath):
install_requires=[
"django>=2.0",
],
python_requires='>=3.6',
python_requires='>=3.7',
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
Expand Down