Once exif data is parsed, do not reload unless it changes #6335
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #6334
The issue features a user calling
im.getexif()
, modifying the exif data, and then saving to a TIFF file.However, when saving TIFF makes sure that the exif data has been read with
getexif()
, which then loads the data withExif.load_from_fp
. This reloads the exif data, overriding the user's changes.The solution is to prevent the exif data from being loaded again if it has already been parsed.
While
Exif.load()
checks that it is not reloading the same input, this is not done forExif.load_from_fp()
. To add that check specifically forload_from_fp
would require storing the file pointer to ensure that it is the same file being read, and storing the file pointer would mean that it needs to be considered as part of the file handling lifecycle.Instead, this PR adds a
_loaded
attribute. Once set,getexif()
does not load the exif data anymore, but just returns the existing object. The attribute is cleared when the exif data is changed by seek operations so that the updated exif data can be loaded.