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

Meta profiling does not work with Django 2.0 and higher #274

Closed
MKolman opened this issue Apr 2, 2018 · 1 comment
Closed

Meta profiling does not work with Django 2.0 and higher #274

MKolman opened this issue Apr 2, 2018 · 1 comment

Comments

@MKolman
Copy link
Contributor

MKolman commented Apr 2, 2018

Problem

In Meta profiling a models.Profile is used. Its ManyToManyField named queries is directly assigned a list of SQLQuery objects. This behaviour has been deprecated in Django 1.10 and removed in Django 2.0.
See actual implementation here.

How to reproduce

Set meta profiling ON by putting the following line in settings.py:

SILKY_META = True

Call any function or view with the profiling turned on

Error

You get the following error:

2018-04-02 16:45:05 [3066] [ERROR] [silk.profiling.profiler::__exit__:40] Exception when performing meta profiling, dumping trace below
Traceback (most recent call last):
  File "/django/path/virtualenv/lib/python3.6/site-packages/silk/middleware.py", line 122, in _process_response
    collector.finalise()
  File "/django/path/virtualenv/lib/python3.6/site-packages/silk/collector.py", line 183, in finalise
    profile.queries = profile_query_models
  File "/django/path/virtualenv/lib/python3.6/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.

Proposed solution

Change direct assignment with .set() method. I will open a PR shortly.

Before

silk/collector.py", line 183, in finalise
    profile.queries = profile_query_models

After

silk/collector.py", line 183, in finalise
    profile.queries.set(profile_query_models)
@MKolman MKolman mentioned this issue Apr 2, 2018
albertyw pushed a commit that referenced this issue Apr 3, 2018
Use `set` method instead of `__set__` on a
`ManyToManyField` to ensure compatibility with
Django 2.0 and higher.
@albertyw
Copy link
Member

albertyw commented Apr 3, 2018

Thanks for the fix.

@albertyw albertyw closed this as completed Apr 3, 2018
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