Go to declaration opens cached file


Every time I ctrl + click on a method/class, Pycharm opens a cached file. 
The path is something like this:


Changes to files are not detected or re-cached. This causes Pycharm to think a method doesn't exist in a file when it actually does, it's just the cache that is stale. To fix this you have to re-start Pycharm which is pretty annoying to do every time you change a file. 

I was able to reproduce the same error in the latest version 2022.3. I confirmed with other devs in my team and we all have the same issue. 

Is there any configuration that can completely invalidate the cache and force it to use the actual file?

Comment actions Permalink

I was able to fix this issue by adding going to File -> Settings -> Project <name of the project> -> Project structure and right-clicking on my project folder and selecting "Sources".

That, however, added a new problem. Now whenever I run tests with the debugger, I can't find some internal libraries that have the same name as my project. 

let's say my project is called foo and I use a library called authentication that is published by my company foo:

from foo.domain.models import User # Class inside foo/domains/models.py
from foo.authentication import JwtDecoder # Class inside the foo-authentication library

This works fine when running the code in a docker container but when running it with the pycharm it raises a ModuleNotFoundError: No module named 'foo.authentication'. It seems that adding the project structure from Pycharm is somehow not allowing python's default behavior to look at other paths before raising a ModuleNotFoundError. Instead, if the module is not found under my projects it'll raise.

Any tips for this issue?

Comment actions Permalink

PyCharm2021.3/remote_sources directory stores a local copy of your remote interpreter (for performance reasons). The issue you are experiencing may appear if you install your project in development mode to your interpreter or with `pip install -e`.

We have a ticket about that in our issue tracker https://youtrack.jetbrains.com/issue/PY-25868/Cant-go-to-declaration-when-using-remote-interpreter-source-and-e-flag

Marking all folders as sources root recursively may help https://youtrack.jetbrains.com/issue/PY-25868/Cant-go-to-declaration-when-using-remote-interpreter-source-and-e-flag#focus=Comments-27-2432104.0-0

Comment actions Permalink

Setting the folders as sources root doesn't fix it for me. 
I am installing my packages with poetry but I am not setting them as editable. 

The weird thing is that any other library works. The only ones that can't be resolved are the ones that have the same name as the project. 

The issue you linked was created 5 years ago, it has priority as "Major" and is still open... I assume this will never be solved. Any other guesses? 


Please sign in to leave a comment.