Skip to content

Fix a crash when expanding two years in a post's Months and Years stats - #26415

Merged
crazytonyli merged 7 commits into
trunkfrom
bugfix/stats-child-row-identity
Nov 26, 2026
Merged

crazytonyli merged 7 commits into
trunkfrom
bugfix/stats-child-row-identity

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes JETPACK-IOS-1ASW: https://a8c.sentry.io/issues/5297452992/

In classic Post Stats, Months and Years and Avg. Views Per Day crash with NSInternalInconsistencyException ("identifiers are not unique") when two expanded years have the same month with the same views. Month rows held only the month name and the count, so April 2026 and April 2025 with 12 views were equal rows, and the diffable table rejected them as duplicates.

Month rows now carry their year and month, and row equality compares it.

Testing:

  • New SiteStatsDetailsPostStatsTests checks the view model's table snapshot. Its four cases fail on trunk and pass with this change.
  • On an iOS 27.2 simulator with locally served post history, trunk crashed on the second expand. This branch keeps both years open.

To test by hand: open a post with the same month and views in two years, then expand both years in Months and Years.

Month rows in Months and Years and Avg. Views Per Day showed only the month
name and views, so the same month with the same views in two expanded years
produced equal rows. The diffable detail table rejected them as duplicate
items and the app crashed. Month rows now carry their year and month, and
row equality compares it.
@crazytonyli
crazytonyli requested a review from jkmassel November 18, 2026 00:56
@crazytonyli crazytonyli added this to the 27.5 milestone Nov 18, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review November 18, 2026 00:57
@wpmobilebot wpmobilebot modified the milestones: 27.5, 27.6 Nov 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.5 has now entered code-freeze, so the milestone of this PR has been updated to 27.6.

@jkmassel jkmassel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From Claude:
Not blocking: the fix is correct and stops the crash. Nothing it breaks turned up.

What we checked

  • Sentry JETPACK-IOS-1ASW: all 11 reports Sentry still keeps are the month-row case, on releases up to 27.4.
  • The new tests pass on this branch (4 cases) and all 4 fail with trunk's StatsDataHelper.swift and StatsTotalRow.swift.
  • iOS 27.2 simulator, Jetpack Debug, New Stats off, post stats served through a local proxy with April at 12 views in both 2026 and 2025. In Months and Years details, the trunk build crashes on the second expand with the same "identifiers are not unique" error as Sentry. This branch keeps both years open, and collapsing and reopening 2026 also works.
  • swift-format and SwiftLint are clean on the changed lines.

A similar crash this PR doesn't cover

Tags and Categories details crashes the same way when two expanded groups share a tag, for example "news, tech" and "news, sport". We reproduced it on a build of this branch. It's older than this PR, so it shouldn't hold this one up; filed as #26458. Making each child row include its parent's identity would cover months, tags and other expandable sections in one place.

Three nits inline.

///
/// Without it, the same month with the same views in two years gives equal rows, and the
/// diffable Stats detail table crashes on the duplicate items when both years are expanded.
var month: DateComponents?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:
Nit: month holds the year as well as the month, and the year is what keeps rows from different years apart. A name like yearMonth would make it harder for someone to fill it with DateComponents(month: 4) later and bring the crash back.

Comment on lines +25 to +26
/// Without it, the same month with the same views in two years gives equal rows, and the
/// diffable Stats detail table crashes on the duplicate items when both years are expanded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:
Nit: this paragraph describes the crash the change fixes, which fits the commit message better. One line is enough here, for example:

Suggested change
/// Without it, the same month with the same views in two years gives equal rows, and the
/// diffable Stats detail table crashes on the duplicate items when both years are expanded.
/// Keeps the same month from different years distinct, since `name` shows only the month.

StatsDataHelper.expandedRowLabelsDetails[section] = years
}

/// Seven years with positive totals, as in the reproduction. 2026 and 2025 both

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:
Nit: "as in the reproduction" points at something a later reader can't open. Dropping that phrase keeps the comment true.

@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

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

@crazytonyli
crazytonyli added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 26, 2026
@crazytonyli
crazytonyli added this pull request to the merge queue Nov 26, 2026
Merged via the queue into trunk with commit d83e3e8 Nov 26, 2026
21 checks passed
@crazytonyli
crazytonyli deleted the bugfix/stats-child-row-identity branch November 26, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants