How to disable automatic variable evaluation when debugging?
Answered
PyCharm's debugger automatically evaluates variables when debugging which is very handy 99.99% of the time. However, this is having a side effect that is really hurting what I am trying to do: log SQL queries generated by each line of code. Since PyCharm is evaluating existing QuerySets and other db related variables, it is querying the database and these hits are getting logged too. You see the problem.
Is there any way to disable that automatic evaluation?
Please sign in to leave a comment.
File | Settings | Build, Execution, Deployment | Debugger | Data Views > disable Enable auto expressions in Variables view
Thank you.
You're welcome!
I changed the setting but it's still calling the `__str__` method. What should I expect to see?
I find that even with this option turned off, the debugger will still evaluate all the attributes of an object (everything decorated with '@property'). This is a problem because I have properties that are expensive to evaluate and do not allow me to carry out proper debugging. Am I misunderstanding this option?
@Tom Edwards
Can you provide example? Does it perhaps help to change variable loading policy to 'on demand'?
Andrey Resler
Here is an example:
If you set a breakpoint at the last line then run the debugger, what will happen is that as soon as you expand the `thing` object in the Variables pane, it will evaluate all the attributes of `thing`.
I tried changing the variable loading policy to 'on demand' but that made no difference.
@ Tom Edwards
Thank you for the example. Unfortunately yes, in this example the code inside the x function will be executed and there's no easy way to suppress that. I think this is worthy of a ticket so here we go: https://youtrack.jetbrains.com/issue/PY-39729
Andrey Resler
Thanks for submitting the ticket!
Thank you Andrey Resler! (and @... for making the ticket). A design mistake I made 14 years ago on my "music21" package (which I didn't fully understand properties) gives some properties bad side-effects -- I wish I could change them to methods, but there's too much usage of the package to make a change like that now.
https://github.com/cuthbertLab/music21/issues/536
Thanks!