Skip to content

Fix GutenbergKit site media selection - #25857

Merged
crazytonyli merged 1 commit into
trunkfrom
fix/custom-post-gallery-media-library
Aug 3, 2026
Merged

Fix GutenbergKit site media selection#25857
crazytonyli merged 1 commit into
trunkfrom
fix/custom-post-gallery-media-library

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

Description

Follow up review comments in #25855

@crazytonyli crazytonyli added this to the 27.1 ❄️ milestone Jul 30, 2026
@crazytonyli
crazytonyli requested a review from dcalhoun July 30, 2026 23:01
@crazytonyli
crazytonyli enabled auto-merge (squash) July 30, 2026 23:02
@wpmobilebot

wpmobilebot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number33581
VersionPR #25857
Bundle IDorg.wordpress.alpha
Commitf8e7e19
Installation URL1fa5ki94et1v0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@wpmobilebot

wpmobilebot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number33581
VersionPR #25857
Bundle IDcom.jetpack.alpha
Commitf8e7e19
Installation URL3gg9o16rduqsg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
crazytonyli changed the base branch from release/27.1 to trunk August 1, 2026 09:48
@crazytonyli
crazytonyli requested a review from a team as a code owner August 1, 2026 09:48
@crazytonyli crazytonyli modified the milestones: 27.1, 27.2 Aug 1, 2026
@crazytonyli
crazytonyli force-pushed the fix/custom-post-gallery-media-library branch from 589483f to f8e7e19 Compare August 3, 2026 05:38
@crazytonyli
crazytonyli requested review from jkmassel and removed request for a team August 3, 2026 05:38

@dcalhoun dcalhoun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me. I performed regression testing in both GBK and GBM on Simple, Atomic, and self-hosted sites. I focused on selecting various file types from the Media Library. I did not encounter any issues.

@crazytonyli
crazytonyli added this pull request to the merge queue Aug 3, 2026
Merged via the queue into trunk with commit e866dc9 Aug 3, 2026
28 checks passed
@crazytonyli
crazytonyli deleted the fix/custom-post-gallery-media-library branch August 3, 2026 21:19
let request = NSFetchRequest<NSManagedObject>(entityName: "Media")
request.predicate = NSPredicate(format: "mediaID IN %@", mediaIds.map { NSNumber(value: $0) })
request.predicate = NSPredicate(
format: "blog == %@ AND mediaID IN %@",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazytonyli question about the blog == %@ constraint this PR added to mapMediaIdsToMedia: Claude flagged it while working on a follow-up in #25866 and I'm not sure whether it's a real problem or not. Below is a summary. WDYT?

The fetch runs on ContextManager.shared.mainContext, but the predicate constrains on blog, which is whatever was passed to GutenbergMediaPickerHelper's initializer:

let context = ContextManager.shared.mainContext
let request = NSFetchRequest<NSManagedObject>(entityName: "Media")
request.predicate = NSPredicate(
    format: "blog == %@ AND mediaID IN %@",
    blog,
    mediaIds.map { NSNumber(value: $0) }
)

A Core Data predicate comparing a relationship against a managed object from a different context matches nothing, so if blog ever belongs to a context other than mainContext, the fetch silently returns no rows and the picker opens with no preselection.

Every path I traced passes a mainContext blog, though I didn't audit this exhaustively — so this may well be unreachable by construction. Is it? If GutenbergMediaPickerHelper is only ever handed a mainContext blog by design, this is a non-issue and I'll leave it alone.

I did try fetching on blog.managedObjectContext locally, but backed it out — SiteMediaCollectionViewController's fetched results controller is hardcoded to mainContext and compares selection by object identity, so that just moves the mismatch somewhere worse.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be okay here. The theory is correct, and we can certainly make the code more robust by not using a Blog instance. But I believe the Blog instance used here is in the main context. It's a convention where the UI related types uses Core Data instance in the main context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing your perspective. Very helpful. 🙇🏻‍♂️

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants