简体   繁体   English

Django Silk分析错误

[英]Django Silk Profiling error

I am trying to use django-silk profiler in my development environment. 我正在尝试在开发环境中使用django-silk profiler。

The page renders successfully but in the console the following error is shown and no profiling data is available in the silk page. 该页面成功呈现,但是在控制台中显示以下错误,并且丝绸页面中没有任何概要分析数据。

Exception when performing meta profiling, dumping trace below
Traceback (most recent call last):
  File "site-packages/silk/middleware.py", line 122, in _process_response
    collector.finalise()
  File "site-packages/silk/collector.py", line 183, in finalise
    profile.queries = profile_query_models
  File "site-packages/django/db/models/fields/related_descriptors.py", line 509, in __set__
    % self._get_set_deprecation_msg_params(),
TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use queries.set() instead.

I am using python 3.6 and django 2.0.3. 我正在使用python 3.6和Django 2.0.3。

Article Database Model: 文章数据库模型:

class Article (models.Model):

    message            =   models.TextField ()
    user               =   models.ForeignKey ( Users,
                             on_delete=models.CASCADE, editable = False, 
                              related_name = 'articles' )

    view_count         =   models.PositiveSmallIntegerField (default = 0 )
    created_at         =   models.DateTimeField ( auto_now_add = True, editable = False )
    updated_at         =   models.DateTimeField ( auto_now = True, editable = False )


    class Meta:
        db_table                =   'articles'
        verbose_name_plural     =   "Articles"

The Users Model is django default user model. 用户模型是django的默认用户模型。

view.py view.py

class ArticleListCreateView(View):

    @silk_profile(name='Article List Profiler')
    def get (self, request, *args, **kwargs):

            ......
             # code for checking permission
             # and setting limit-offset variable
            ......
        try:            

            articles    =   Article.objects.filter(user=request.session.user).order_by('-created_at'
                            ).values('message', 'view_count')[offset:limit]

        except Exception as e:
            raise CustomException ('Server Error. Unable To Retrive Articles', 500)

        return JsonResponse( articles, safe = False )   

Go to the file collector.py of the silk package and change the line 183 from: 转到Silk包的文件collector.py并将183行更改为:

profile.queries = profile_query_models

to: 至:

profile.queries.set(profile_query_models)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM