PyCharm should detect relative paths in Analyze Stacktrace

Answered

Hey all! I am on PyCharm Pro 2018.1.3.

I have noticed a behavioral oddity while attempting to use the Analyze Stack functionality with an external stack trace: PyCharm does not play well with relative paths. Easier to explain with an example:

Exhibit A works

File "/users/myuser/myproj/thing.py", line 50, in main

Exhibit B does not work

File "myproj/thing.py", line 50, in main

Am I misconfigured somewhere? How can I work around this? Is this something that might be remedied in a future version?

Cheers

5 comments

Hi bestsharper! Could you please provide a code snippet to generate such stacktrace?

1

Sure, easy enough.

 

Consider this basic code snippet:

def foo():
raise Exception()

foo()

Save it as test.py in your home directory (e.g. /Users/myuser/test.py).

Execute it: python /Users/myuser/test.py

You will receive the following stack:

Traceback (most recent call last):
File "/Users/myuser/test.py", line 4, in <module>
foo()
File "/Users/myuser/test.py", line 2, in foo
raise Exception()
Exception

You can now plug that into PyCharm with Analyze Stacktrace and have the code navigable to the exact line.

However, try mangling the path to the file making it different from where it is located on local (or at the time the stack was obtained):

- pretend you have deployed the code on a live env and replace /Users/myuser with a different path

- execute the code without a full path, aka python test.py which will omit the full path from the stack

- move the file to a new location before opening it

For example,

Traceback (most recent call last):
File "/my/deployed/environment/test.py", line 4, in <module>
foo()
File "/my/deployed/environment/test.py", line 2, in foo
raise Exception()
Exception

Plugging that stack in causes PyCharm to not perform any analysis.

 

The application here is analyzing stack traces not produced by local machine (e.g. other devs or prod/qa/other envs):

/my/local/dev/services/apis/foo.py

vs

/production/deploy/services/apis/foo.py

The issue here is that prod stacks will never match whatever the paths local dev might have. One work-around is to find-replace the part of the path that does not match, but it seems like an IDE ought to be able to do something with the info it has.

0

I'm experiencing the same frustration while using PyCharm on the host machine and running tests in a VM.

0

Reproduced the issue by changing script path in the run configuration from absolute to relative.

@Pavel Karateev

Do you have any input?

0

Please vote for the corresponding feature requests:

  • PY-25526 Analyze stacktrace does not recognize path mapping from remote interpreter
  • PY-10501 Stack analysis fails if path prefix doesn't match
0

Please sign in to leave a comment.