Skip to content

Bugfix/fix reuse last entered value - #4668

Open
xkello wants to merge 4 commits into
masterfrom
bugfix/fix-reuse-last-entered-value
Open

Bugfix/fix reuse last entered value#4668
xkello wants to merge 4 commits into
masterfrom
bugfix/fix-reuse-last-entered-value

Conversation

@xkello

@xkello xkello commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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.
  • 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.

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.

@xkello
xkello requested a review from Withalion August 25, 2026 12:43
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build Build failed or not found. #7212
linux Build Build failed or not found. #7238
win64 Build 📬 Mergin Maps 64141 win64 Expires: 23/11/2026 #6414
Android Build 📬 Mergin Maps 852351 APK [arm64-v8a] Expires: 23/11/2026 #8523
📬 Mergin Maps 852351 APK [arm64-v8a] Google Play Store #8523
Android Build 📬 Mergin Maps 852311 APK [armeabi-v7a] Expires: 23/11/2026 #8523
📬 Mergin Maps 852311 APK [armeabi-v7a] Google Play Store #8523
iOS Build 📬 Build number: 26.08.946411 #9464

@github-actions

Copy link
Copy Markdown

Coverage Report for CI Build 32851633524

Warning

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.064%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 15766
Covered Lines: 9312
Line Coverage: 59.06%
Coverage Strength: 96.96 hits per line

💛 - Coveralls

@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 72131 dmg Expires: 23/11/2026 #7213
linux Build 📬 Mergin Maps 72391 x86_64 Expires: 23/11/2026 #7239
win64 Build 📬 Mergin Maps 64151 win64 Expires: 23/11/2026 #6415
Android Build 📬 Mergin Maps 852451 APK [arm64-v8a] Expires: 23/11/2026 #8524
📬 Mergin Maps 852451 APK [arm64-v8a] Google Play Store #8524
Android Build 📬 Mergin Maps 852411 APK [armeabi-v7a] Expires: 23/11/2026 #8524
📬 Mergin Maps 852411 APK [armeabi-v7a] Google Play Store #8524
iOS Build 📬 Build number: 26.08.946511 #9465

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.

"reuse last entered value" not working for attachment/photos fields

1 participant