test(cli): fix default-language test env state, not just retry (#35780)#35813
Conversation
Diagnosis of the latest CLI failure showed the SiteAPIIT failure is
deterministic, not a timing race. The CI dotCMS instance returns:
{"language":"LANG__404", "id":-1, "defaultLanguage": true},
{"language":"English", "id": 1, "defaultLanguage": false}
Bumping retries or backoff cannot fix this — the default is permanently
the LANG__404 sentinel (id=-1). The existing warmup passed because it
only verified that ANY language had id>0 (English does), not that the
DEFAULT language had id>0.
This strengthens the warmup:
- After listing, check whether the entry marked defaultLanguage=true
actually has id>0. If yes, we are done.
- If not, pick the first language with id>0 (English in starter data)
and call PUT /api/v2/languages/{id}/_makedefault with
fireTransferAssetsJob=false to fix the broken state.
- Re-list to confirm before declaring success.
Adds the corresponding makeDefault() method to the CLI LanguageAPI
interface so the warmup can call the endpoint via the existing
Quarkus REST client.
The retry-on-language-null workaround from #35803 is preserved as
defense-in-depth, but should not be needed if the warmup succeeds.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @dsolistorres's task in 2m 31s —— View job dotCMS Backend Review
All four sub-agents (Security, Database, Java Standards, REST API) returned NO_FINDINGS. The PR is scoped entirely to Posted the clean review marker comment: #issuecomment-4521705371.
|
|
✅ dotCMS Backend Review: no issues found. |
Summary
Follow-up to PR #35803 (the retry workaround). After that PR merged, the CLI tests in
SiteAPIITwere still failing. Diagnosing the latest run (26301904102) showed this is not a timing race — it is deterministic test-environment state.What the diagnosis showed
17:55:44. First failing test ran at17:56:05— 21 seconds later. Cache fully populated by then.warmLanguageCacheIfNeeded()warmup succeeded on its first attempt (HTTP 200).retryOnLanguageNullretry from test(cli): retry SiteAPIIT.create on transient 'Language cannot be null' (#35780) #35803 did fire (test elapsed went from ~250ms → ~1100ms = 3 attempts × ~250ms backoff). All three attempts hit the same 500 error.But look at what the warmup response actually contains:
{ "entity": [ {"language": "LANG__404", "id": -1, "defaultLanguage": true}, {"language": "English", "id": 1, "defaultLanguage": false} ] }The "default language" is permanently the
LANG__404sentinel (id=-1). English exists with id=1 but is not marked default. So:SiteResource.create()callsgetDefaultLanguage().getId()→ gets-1languageId = -1UniqueFieldCriteriacallsgetLanguage(-1)→ returns nullObjects.requireNonNull(language, "Language cannot be null")→ NPE → HTTP 500The existing warmup passed because it only verified that any language had
id > 0(English does). It did not verify that the default language hadid > 0.What this PR changes
LanguageAPI.java(CLI interface) — adds:SiteAPIIT.warmLanguageCacheIfNeeded()— strengthens the warmup:defaultLanguage=truehasid > 0, we are done.id > 0(English in starter data) and callPUT /api/v2/languages/{id}/_makedefaultwithfireTransferAssetsJob=falseto fix the broken default.The
retryOnLanguageNullworkaround from #35803 is preserved as defense-in-depth around the 4.create(...)call sites — if the warmup somehow doesn't fix the state, the retry will still try. But it should not be needed.Why this works when retries do not
Retries assume a transient state that will clear if we wait. The CI evidence shows the state is stable —
getDefaultLanguage()returnsLANG__404every time, indefinitely. Only an actionable fix (forcing a real language as the default) changes that state._makedefaultis the same endpoint the dotCMS admin UI uses for "switch default language".fireTransferAssetsJob=falseskips the heavy background job, so the call is a fast metadata update — appropriate for test setup.What this PR does NOT do
LANG__404as the default in the first place — is left for a future investigation tracked under Flaky Postman tests: WorkflowResource silently defaults missing languageId to -1L causing FK violation #35780.SiteAPIITandLanguageAPI. No production CLI code paths affected.Test plan
./mvnw test-compile -pl :dotcms-api-data-model→BUILD SUCCESS.retryOnLanguageNull).PR Test / CLI Testsshould pass on this branch.🤖 Generated with Claude Code
This PR fixes: #35780