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?

2
10 comments

File | Settings | Build, Execution, Deployment | Debugger | Data Views > disable Enable auto expressions in Variables view

0
Avatar
Permanently deleted user

Thank you.

0

You're welcome!

 

0

I changed the setting but it's still calling the `__str__` method. What should I expect to see?

0
Avatar
Permanently deleted user

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?

0

@Tom Edwards

Can you provide example? Does it perhaps help to change variable loading policy to 'on demand'? 

0
Avatar
Permanently deleted user

Andrey Resler

Here is an example:

class Thing:
y = 1

@property
def x(self):
print("ACCESSING Thing.x")
return 2

thing = Thing()
pass

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. 

0

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

1
Avatar
Permanently deleted user

Andrey Resler

Thanks for submitting the ticket! 

0

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!

0

Please sign in to leave a comment.