spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.22k stars 1.59k forks source link

Unable to Save after Renaming Directory #17241

Open primkey7607 opened 2 years ago

primkey7607 commented 2 years ago

Description

What steps will reproduce the problem?

I believe this issue occurred because I tried saving a file I was still working on after renaming the directory the file was in. Here are the steps:

  1. Create a directory with a file inside, as part of a spyder project.
  2. Create a new file in the directory, but don't save the file.
  3. Rename the directory.
  4. Try to save the file.
  5. You should get an error message asking if you want to close the file. Say 'yes'.
  6. You should get another error message saying the file was modified, and asking if you want to save the file. Say 'yes'.
  7. You should see your usual window with directories. Choose the directory you just renamed.
  8. You should get a message saying that the file already exists, do you want to replace it? Say yes.
  9. Then, spyder has an internal error.

I think this should be enough to reproduce this error.

Traceback

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.8/site-packages/spyder/plugins/editor/plugin.py", line 2404, in renamed_tree
    self.renamed(source=fname, dest=new_filename)
  File "/opt/anaconda3/lib/python3.8/site-packages/spyder/plugins/editor/plugin.py", line 2392, in renamed
    editorstack.rename_in_data(filename,
  File "/opt/anaconda3/lib/python3.8/site-packages/spyder/plugins/editor/widgets/editor.py", line 1358, in rename_in_data
    self.set_current_filename(current_fname)
  File "/opt/anaconda3/lib/python3.8/site-packages/spyder/plugins/editor/widgets/editor.py", line 1519, in set_current_filename
    editor = self.data[index].editor
IndexError: list index out of range

Versions

Dependencies


# Mandatory:
applaunchservices >=0.1.7     :  0.2.1 (OK)
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.29.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.0 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.2 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.4 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.3 (OK)
qtconsole >=5.1.0             :  5.1.1 (OK)
qtpy >=1.5.0                  :  1.10.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  58.0.4 (OK)
sphinx >=0.6.6                :  4.2.0 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.3 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  0.29.25 (OK)
matplotlib >=2.0.0            :  3.5.0 (OK)
numpy >=1.7                   :  1.21.2 (OK)
pandas >=1.1.1                :  1.3.4 (OK)
scipy >=0.17.0                :  1.7.1 (OK)
sympy >=0.7.3                 :  1.9 (OK)
dalthviz commented 2 years ago

Hi @primkey7607 thank you for the feedback! I was unable to reproduce this with the latest Spyder (version 5.2.2). Could you check with that version?

For that you will need to create a new env to install Spyder from the conda-forge channel:

 conda create -n spyder_env python=3.8 spyder=5.2.2 -c conda-forge

or use our MacOS installer: https://github.com/spyder-ide/spyder/releases/download/v5.2.2/Spyder.dmg

Let us know if something of the above helps!

primkey7607 commented 2 years ago

Hi @dalthviz thanks for the quick followup! I finally got around to updating to spyder 5.2.2, and it worked--I am unable to reproduce the issue as well.

However, I'm really sorry--I tried following my own instructions and couldn't reproduce the issue on 5.1.5 (the version I was using), either!

But I know now when this issue occurs: it occurs specifically when I create a file in a directory, but don't save it, and then change the directory name (rather than just writing to a file that already existed in the directory). I edited my issue description to explain this better. Hopefully that will help. Also, I get this problem on 5.2.2 as well.

dalthviz commented 2 years ago

Hi again @primkey7607 thank you for providing new info! With the new steps I was able to reproduce this! We will check it in a future release :+1:

dalthviz commented 2 years ago

Just in case when checking this I also get from the Anaconda prompt from where I launched spyder the following:

ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
primkey7607 commented 2 years ago

Just in case when checking this I also get from the Anaconda prompt from where I launched spyder the following:

ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py
ERROR:spyder.plugins.editor.utils.autosave:KeyError when retrieving hash of D:\Acer\Documentos\Spyder\Proyectos\test1\testing_rename\tests.py

Yes, I see similar messages on the anaconda prompt as well on my end.