Crash in PostCategory.lookup ("nil is not a valid object ID") after a quick status change from the post list

Đang mở
#26,316 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
objective-c, swift
Lĩnh vực
mobile

Hướng nghiên cứu

Build the Jetpack scheme and use docs/simulator-sign-in.md to set up the simulator. Follow the listed steps with Network Link Conditioner, then inspect PostRepository.update, PostHelper.merge, and the PostCategory.lookup stack path to check whether the post is deleted while the PATCH is in flight. Report whether the repro is reliable and, if confirmed, the cause and a fix approach.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

[Status] Needs Plan [Type] Crash Core Data Posts + Pages

Likely shares a root cause with #26317, #26318, #26319, #26320. See #26323: posts are deleted locally by a first-page list sync while still in use.

Sentry: JETPACK-IOS-1JSW

Sentry snapshot (as of Oct 30, 2026)

  • Fatal NSInvalidArgumentException: nil is not a valid object ID. First seen Mar 21, 2026. 373 events from 149 users in total.
  • Last 30 days by release:
    • 27.3: 138 events, 78 users
    • 27.2: 12 events, 10 users
    • 27.1: 2 events
  • This got worse in 27.3. 27.3 has about 4.2× as many users reporting any error as 27.2 (2,388 vs 573 in 30 days). This crash is at about 7.8× on 27.3, so it's roughly twice as frequent per user.
  • Devices: iPhone only, with no iPad events. Mostly iOS 26.3–26.6 and 27.0.x.

Stack (crashing thread)

PostCoordinator.performChanges closure (PostCoordinator.swift:252) → PostCoordinator.update (:156) → PostRepository.update (PostRepository.swift:216) → +[PostHelper updatePost:withRemotePost:inContext:overwrite:] (PostHelper.m:89) → updatePost:withRemoteCategories: (:113) → PostHelper.createOrUpdateCategory (PostHelper+Metadata.swift:42) → PostCategory.lookup (PostCategory+Lookup.swift:19) → NSManagedObjectContext existingObjectWithID: throws.

createOrUpdateCategory passes blog.objectID. The blog comes from post.blog, which is nil here. existingObject(with:) then raises an Objective-C exception, which the try? in the caller can't catch.

Breadcrumbs (6 recent 27.3 events)

In all 6, the crash happens just as a quick PATCH (POST …/posts/{id}?context=edit) returns, after the user started it from the post list:

  • 3 of 6: a context-menu action from the Published tab, with an 18-byte body. That's {"status":"draft"}, i.e. Move to Draft (PostCoordinator.moveToDraft).
  • 2 of 6: Publish from the Drafts tab via PublishPostViewController, with a 20-byte body (status → publish).
  • 1 of 6: a Post Settings save from the list's context menu (42–98 byte body).
  • In every one, the same list status (status=publish,private or status=draft,pending) was re-fetched while the PATCH was in flight. Several events show the list polling every few seconds.

Candidate cause (hypothesis, not confirmed)

  1. The user changes a post's status from the list. The PATCH starts, and the server applies it right away.
  2. The list for the old status re-syncs. The post isn't in the response anymore, so PostRepository (purgeExisting: deleteOtherLocalPosts) → PostHelper.merge (PostHelper.m:193) deletes the local post.
  3. The PATCH response arrives. PostRepository.update calls PostHelper.update(post, …) on the deleted object. post.blog is nil, so it crashes.

Possible fixes:

  • In PostRepository.update, return early after the await if post.isDeleted or post.managedObjectContext == nil.
  • Make PostHelper updatePost:withRemoteCategories: skip the update when post.blog is nil.
  • Exclude posts with an update in flight from the purge.

Why 27.3 is worse is unclear. Nothing in the 27.2→27.3 range (e7c3606158…b2234d0688) touches PostRepository, PostCoordinator or the purge. #25970 only changed PostCategoryService create, which isn't on this path. The frequent list polling seen in the breadcrumbs is worth checking.

Repro to try, in order

  1. Setup: a WordPress.com site with a few published posts and drafts. Use Network Link Conditioner (host) with ~3 s latency so the PATCH stays in flight.
  2. Move to Draft: Posts › Published › long-press a post › Move to Draft. Immediately pull to refresh the Published list.
  3. Publish: Posts › Drafts › context menu › Publish › confirm. Immediately pull to refresh the Drafts list.
  4. Repeat steps 2 and 3 about 10 times. Add an Exception breakpoint, plus a breakpoint where PostHelper.merge deletes posts, to confirm the post is deleted before PostRepository.update resumes.

Event IDs

  • 47cf73bc5efd408f99dc69bda3765d25: Move to Draft, Published tab
  • 330d0c02d72e46858ac56b3c6cdd1e8b: Move to Draft, Published tab
  • ed467d1d01f740b2bbe4891bbbda9933: Publish from Drafts
  • fc8a713c1270408a9933b50a00baa747: Post Settings save, then Publish from Drafts
  • 864cdb7293b8437197cecd2a7a314574: Post Settings save from the Published tab

Build the Jetpack scheme and sign in using docs/simulator-sign-in.md, with bundle ID com.automattic.jetpack.

When you're done: post the results here. If you now have reliable steps, remove [Status] Needs Repro. If you found the cause and a fix approach, remove [Status] Needs Plan and add [Status] Ready for Dev. Remove Simulator Testable when you're finished.


Generated by Claude Code

Ngôn ngữ chính
Swift
Star
3.9k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
136

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wordpress-mobile/WordPress-iOS

Tất cả issue của wordpress-mobile/WordPress-iOS

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.