You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes a bug where enabling "Use last entered value" on a photo/file field causes the previous feature's photo file to be corrupted, renamed, or orphaned when reused by a new feature - most visibly when a custom filename expression is set in QGIS, where the previous feature's file gets physically renamed and reassigned to the new feature, leaving the previous feature with a broken/missing image.
AttributeController::updateOnFeatureChange() now clones the underlying file when a photo/file field's value is reused, instead of just copying the path string. Each feature gets its own independent file from the moment the drawer opens, so it's never possible for two features to end up sharing (and therefore corrupting) the same photo.
The clone is tracked on the FormItem (isReusedValue(), reusedCopyPath()) so it can be cleaned up if it's never actually needed: AttributeController::discardReusedPhotoCopies() deletes it if the draft feature is discarded (cancel/rollback), or if the photo is deleted or replaced before the feature is saved.
renamePhotos() now evaluates the project's custom filename expression fresh against the clone (instead of skipping reused fields entirely), so a reused photo gets a correctly computed, per-feature filename rather than a generic incremented name. A static expression that collides with an existing file still gets a proper incremental suffix.
recalculateDefaultValues() no longer lets a QGIS field-level Default Value expression overwrite a value that was just populated by "reuse last entered value" while the form is open.
InputUtils::resolveTargetDir() now resolves a relative root path expression/Default Path against the project home path. Previously a relative path (e.g. 'photos/' + @layer_name) was used as-is, which could resolve to the wrong location on disk and produce a broken/missing image.
Android (MMActivity.importImage) and iOS (IOSGalleryPickerDelegate) gallery import now create the destination directory before copying the picked image, matching what capture-from-camera already did.
Behaviour
Reusing a photo value for a new feature clones the file, so previously saved features keep their original, valid photo path - no more orphaned attachments or broken image icons after sync.
Deleting or unlinking a reused photo from one feature no longer affects any other feature that reused it.
Cancelling a draft feature, or deleting/replacing a reused photo before saving, cleans up the clone instead of leaving it behind.
Custom filename expressions are evaluated fresh for each feature's cloned photo, with correct incremental suffixing when the expression is static.
No impact on fields without a custom filename expression, and no impact on the "unsaved changes" dialog.
"Use last entered value" on a photo field now clones the file per feature instead of sharing/renaming the original, so reused photos never corrupt or orphan another feature's image, on save or on cancel.
No base build found for commit ad2d3fa on master.
Coverage changes can't be calculated without a base build. If a base build is processing, this comment will update automatically when it completes.
Coverage: 59.28%
Details
Patch coverage: No coverable lines changed in this PR.
The reason will be displayed to describe this comment to others. Learn more.
Looks like in some cases the photo renaming doesn't work correctly. Either it get's renamed again, when using now() or the name somehow gets mixed with previous value as well. Have a look at this project Matej-test/photo-naming-expr and POI layer.
Renaming gets triggered on empty photo fields with reuse last entered value turned on.
My comment on the issue about unlinking/deleting is addressed by #4685?
Add some unit tests for using default value on photos in testattributecontroller.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Description
Fixes a bug where enabling "Use last entered value" on a photo/file field causes the previous feature's photo file to be corrupted, renamed, or orphaned when reused by a new feature - most visibly when a custom filename expression is set in QGIS, where the previous feature's file gets physically renamed and reassigned to the new feature, leaving the previous feature with a broken/missing image.
Fixes: #4487
What changed
AttributeController::updateOnFeatureChange()now clones the underlying file when a photo/file field's value is reused, instead of just copying the path string. Each feature gets its own independent file from the moment the drawer opens, so it's never possible for two features to end up sharing (and therefore corrupting) the same photo.FormItem(isReusedValue(),reusedCopyPath()) so it can be cleaned up if it's never actually needed:AttributeController::discardReusedPhotoCopies()deletes it if the draft feature is discarded (cancel/rollback), or if the photo is deleted or replaced before the feature is saved.renamePhotos()now evaluates the project's custom filename expression fresh against the clone (instead of skipping reused fields entirely), so a reused photo gets a correctly computed, per-feature filename rather than a generic incremented name. A static expression that collides with an existing file still gets a proper incremental suffix.recalculateDefaultValues()no longer lets a QGIS field-level Default Value expression overwrite a value that was just populated by "reuse last entered value" while the form is open.InputUtils::resolveTargetDir()now resolves a relative root path expression/Default Path against the project home path. Previously a relative path (e.g.'photos/' + @layer_name) was used as-is, which could resolve to the wrong location on disk and produce a broken/missing image.MMActivity.importImage) and iOS (IOSGalleryPickerDelegate) gallery import now create the destination directory before copying the picked image, matching what capture-from-camera already did.Behaviour
TLDR @Withalion
"Use last entered value" on a photo field now clones the file per feature instead of sharing/renaming the original, so reused photos never corrupt or orphan another feature's image, on save or on cancel.