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

有个bug #260

Closed
fvaryu opened this issue May 8, 2019 · 3 comments
Closed

有个bug #260

fvaryu opened this issue May 8, 2019 · 3 comments

Comments

@fvaryu
Copy link

fvaryu commented May 8, 2019

注意注释, 可能不是这里报错,我自己分析的 未配置第三方 applications是字符串‘default', 而且非毕现。
报错信息,str没有属性ICON_NAME

@register.inclusion_tag('oauth/oauth_applications.html')
def load_oauth_applications(request):
    applications = get_oauth_apps()  # 此处会从缓存获取
    if applications:
        baseurl = reverse('oauth:oauthlogin')
        path = request.get_full_path()

        print('===========', applications)

        apps = list(map(lambda x: (x.ICON_NAME,
                                   '{baseurl}?type={type}&next_url={next}'
                                   .format(baseurl=baseurl, type=x.ICON_NAME, next=path)), applications))
    else:
        apps = []
@cache_decorator(expiration=100 * 60) # 使用装饰器
def get_oauth_apps():
#    略
def cache_decorator(expiration=3 * 60):
    # 略
# 如果没有从缓存取到会执行下面的流程
            else:
                value = func(*args, **kwargs)
                logger.info('cache_decorator set cache:%s key:%s value:%s' % (func.__name__, key, value))
# 如果没有配置第三方 执行if后面的代码 此时设置缓存为default 是个str
                if not value:
                    cache.set(key, 'default', expiration)
                else:
                    cache.set(key, value, expiration)
                return value

        return news

    return wrapper

下次 在执行这个流程的时候缓存就会有值 并且是str类型的default,然后得到的applications就是str,执行apps = list(map(lambda x: (x.ICON_NAME, '{baseurl}?type={type}&next_url={next}' .format(baseurl=baseurl, type=x.ICON_NAME, next=path)), 这个的时候就会报错,str没有icon_name属性

@liangliangyy
Copy link
Owner

liangliangyy commented May 8, 2019

你好,感谢你的提醒,不过这个bug以前已经修复了,请见:
https://github.com/liangliangyy/DjangoBlog/blob/master/DjangoBlog/utils.py#L57-L60
建议你直接获取最新代码,不用从release来下载,release已经很久没有更新了。

@fvaryu
Copy link
Author

fvaryu commented May 9, 2019

我这个就是最新的 还会有 偶尔,主要出现在使用runserver,线上出现次数不多

@liangliangyy
Copy link
Owner

#262 是同一个bug

liangliangyy added a commit that referenced this issue May 11, 2019
hermanzhaozzzz pushed a commit to hermanzhaozzzz/DjangoBlog that referenced this issue Aug 15, 2021
hermanzhaozzzz pushed a commit to hermanzhaozzzz/DjangoBlog that referenced this issue Aug 15, 2021
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

No branches or pull requests

2 participants