Skip to content

Fix resized source image dimension persistence - #678

Open
jihtsan wants to merge 1 commit into
SmileyChris:masterfrom
jihtsan:codex/548-save-resized-dimensions
Open

jihtsan wants to merge 1 commit into
SmileyChris:masterfrom
jihtsan:codex/548-save-resized-dimensions

Conversation

@jihtsan

@jihtsan jihtsan commented Oct 28, 2026

Copy link
Copy Markdown

Fixes #548.

Save a pending resized source before Django collects the model's column values. When width/height columns precede the image field, a regular model save now persists the dimensions of the stored resized image instead of the original upload. Register the preparation only for models using resize_source with dimension fields, including inherited fields; respect raw saves and update_fields, and avoid reprocessing committed files.

Validation on macOS, Python 3.12.14 and Pillow 13.0.0:

  • The original source fails five of the initial six regressions; an actual SQLite/file probe shows database dimensions 400×200 for a 100×50 stored image.
  • Django 5.2.18: full suite 132 passed, 4 optional SVG tests skipped.
  • Django 4.2.30: full suite 132 passed, 4 optional SVG tests skipped.
  • Seven added cases cover creation, replacement, explicit image save, selected/unrelated partial updates, concrete model inheritance and raw saves.
  • git diff --check passes; separate Standards and Spec reviews completed against the submitted SHA.

The test environment needs its virtualenv on PATH because the existing mock optimizer uses /usr/bin/env python. Initial runs without that PATH failed that existing subprocess test; both complete runs pass with the normal activated-venv PATH. No test was skipped to work around it.

Django 5.1, other Python versions/operating systems and SVG extras were not run. Bulk operations bypassing Model.save/signals are outside this change. As with Django's ImageField, update_fields must include the dimension columns when those values should be persisted.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThumbnailerImageField saves incorrect width_field and height_field when resize_source is applied

1 participant