简体   繁体   中英

Django Silk Profiling error

I am trying to use django-silk profiler in my development environment.

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.

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.

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:

profile.queries = profile_query_models

to:

profile.queries.set(profile_query_models)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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