Uploaded image for project: 'Picard'
  1. Picard
  2. PICARD-1375

Metadata sanitation before move-script execution fails

    Details

      Description

      When sanitation of metadata occurs before executing the move script (due to slash/backslash in any metadata tag), it fails with the following traceback:

       

      E: 11:47:25,245 /usr/lib/python3.7/site-packages/picard/util/thread.run:51: Traceback (most recent call last):
        File "/usr/lib/python3.7/site-packages/picard/util/thread.py", line 47, in run
          result = self.func()
        File "/usr/lib/python3.7/site-packages/picard/file.py", line 218, in _save_and_rename
          new_filename = self._rename(old_filename, metadata)
        File "/usr/lib/python3.7/site-packages/picard/file.py", line 380, in _rename
          self._make_filename(old_filename, metadata))
        File "/usr/lib/python3.7/site-packages/picard/file.py", line 349, in _make_filename
          new_filename = self._script_to_filename(naming_format, metadata, settings)
        File "/usr/lib/python3.7/site-packages/picard/file.py", line 305, in _script_to_filename
          for name in metadata.keys():RuntimeError: dictionary changed size during iteration
      
      

      This is an issue with different behavior of dict.keys() in Python 2 (creates copy of keys) and Python 3 (iterates over original keys), because the dictionary is being altered while iterating over it.

      It can be fixed (somewhat dirty) by converting keys to a list in file.py, _script_to_filename():

       

      # make sure every metadata can safely be used in a path name
              for name in list(metadata.keys()):
                  if isinstance(metadata[name], str):
      ...
      

       

      I don't have the time to look into this, but the issue could also affect further parts of Picard >2.0 where a dictionary is changed while iterating over it.

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                outsidecontext Philipp Wolfer
                Reporter:
                carstenl carstenl
              • Votes:
                1 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: