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.

Django 3.0.5 compatibility problem

See original GitHub issue

Hello I’m using Django 3.0.5 and django.utils.decorators.available_attrs is not supported anymore but it is used in lazysignup/decorators.py. I have substituted it with WRAPPER_ASSIGNMENTS as suggested in the docs and this it works fine:

from functools import wraps

from django.conf import settings
from django.contrib.auth import SESSION_KEY
from django.contrib.auth import authenticate
from django.contrib.auth import get_user
from django.contrib.auth import login
from django.shortcuts import redirect
from functools import WRAPPER_ASSIGNMENTS

from lazysignup.constants import USER_AGENT_BLACKLIST
from lazysignup.utils import is_lazy_user

ALLOW_LAZY_REGISTRY = {}


def allow_lazy_user(func):
    def wrapped(request, *args, **kwargs):
        assert hasattr(request, 'session'), ("You need to have the session "
                                             "app installed")
        if getattr(settings, 'LAZYSIGNUP_ENABLE', True):
            # If the user agent is one we ignore, bail early
            ignore = False
            request_user_agent = request.META.get('HTTP_USER_AGENT', '')
            for user_agent in USER_AGENT_BLACKLIST:
                if user_agent.search(request_user_agent):
                    ignore = True
                    break

            # If there's already a key in the session for a valid user, then
            # we don't need to do anything. If the user isn't valid, then
            # get_user will return an anonymous user
            if get_user(request).is_anonymous and not ignore:
                # If not, then we have to create a user, and log them in.
                from lazysignup.models import LazyUser
                user, username = LazyUser.objects.create_lazy_user()
                request.user = None
                user = authenticate(username=username)
                assert user, ("Lazy user creation and authentication "
                              "failed. Have you got "
                              "lazysignup.backends.LazySignupBackend in "
                              "AUTHENTICATION_BACKENDS?")
                # Set the user id in the session here to prevent the login
                # call cycling the session key.
                request.session[SESSION_KEY] = user.id
                login(request, user)
        return func(request, *args, **kwargs)

    return wraps(func)(wrapped)


def require_lazy_user(*redirect_args, **redirect_kwargs):
    def decorator(func):
        @wraps(func, assigned=WRAPPER_ASSIGNMENTS)
        def inner(request, *args, **kwargs):
            if is_lazy_user(request.user):
                return func(request, *args, **kwargs)
            else:
                return redirect(*redirect_args, **redirect_kwargs)
        return inner
    return decorator


def require_nonlazy_user(*redirect_args, **redirect_kwargs):
    def decorator(func):
        @wraps(func, assigned=WRAPPER_ASSIGNMENTS)
        def inner(request, *args, **kwargs):
            if not is_lazy_user(request.user):
                return func(request, *args, **kwargs)
            else:
                return redirect(*redirect_args, **redirect_kwargs)
        return inner
    return decorator

Sorry if I might have missed something or not used the right format but be patient this is the first issue that I open. Hope it helped 😃

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
NerdPraisecommented, Dec 21, 2020

This issue still haven’t been fixed

2reactions
MattFantocommented, Nov 29, 2021

@Jazzthedog depends on what you are using (poetry pipenv, …) the pip command should be something like

pip install git+https://github.com/danfairs/django-lazysignup@42470be
Read more comments on GitHub >

github_iconTop Results From Across the Web

Django 3.0.5 release notes - Documentation
Fixed a regression in Django 3.0 where QuerySet.values() and values_list() crashed if a queryset contained an aggregation and Subquery() ...
Read more >
Not working for django version greater than 3.0 #364 - GitHub
One line description of the issue. Unable to integrate into Django version greater than 3.0. ERROR: djongo 1.3.0 has requirement django<3 ...
Read more >
Django@3.0.5 - Snyk Vulnerability Database
Affected versions of this package are vulnerable to Web Cache Poisoning. Django contains a copy of urllib.parse.parse_qsl() which was added to backport some ......
Read more >
pip can't find django 3.x - ERROR: No matching distribution ...
When you use a Python version lower than that to run pip install (on your local machine) then only compatible versions are listed....
Read more >
django-filter - PyPI
Support for Python and Django versions will be dropped when they reach end-of-life. Support for Python versions will dropped when they reach end-of-life,...
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