ohmg-dev / OldInsuranceMaps

A public space for georeferencing historical fire insurance maps.
https://oldinsurancemaps.net
GNU General Public License v3.0
17 stars 2 forks source link

[Bug] Undo split and undo georeferencing can leave messy artifacts #170

Open mradamcox opened 4 months ago

mradamcox commented 4 months ago

Describe the problem I found an example last night as follows: A sheet had been split into four pieces, but two were undesirable artifacts from the process (due to a messy cut-line). To fix this I un-georeferenced the two good pieces that had been georeferenced, and then un-prepared the parent sheet. This all seemed to go as desired. When I re-prepared the sheet, now splitting into 2 different pieces, this also seemed to work, at first. However, viewing one of the detail pages for the new pieces, the preview was distorted, and, similarly, the left side of the georeferencing interface was distorted. The problem seemed to be that the old dimensions for the previously split piece were somehow cached and being applied to the newly created piece. Especially puzzling was the fact that the actual file on disk for this piece wasn't distorted, it was fine, so it was just the image size that was stored in document.image_size (a @cached_property attribute) was not properly updated. This was especially confusing because these new pieces were completely new database objects, and, seemingly, the files had been properly regenerated.

Ultimately, with a lot of mucking around, I think I figured out that the old file pieces were still around in the file system, and they were causing problems. Also, the entries for the georeferenced layers in the MultiMask and in the "sorted_layers" key on the volume had not been removed (causing other issues).

Expected behavior Undoing a preparation or georeferencing session should properly clean up ALL remnants of the old files.

To Reproduce Steps to reproduce the behavior:

  1. Split a document into multiple pieces
  2. Georeference one of them
  3. Trim the layer in the MultiMask
  4. Undo all steps
  5. Re-split the document into a smaller number of pieces
  6. The image preview for the new pieces should look wrong, they should be expecting a file of the wrong dimensions.

Additional context

It would be good, especially to help with debugging and corrective measures, to change document.image_size from a cached property to a normal attribute on the model (I was never able to tell why exactly the old size was being reported, but this would just be a good thing to do). image_size should be set every time the document is saved (I don't think this would impact performance, because they aren't modified/saved especially often).

Additionally, the following must be addressed: