Skip to content

fix(organisations): don't fetch an organisation with a non-numeric id - #8222

Draft
talissoncosta wants to merge 3 commits into
mainfrom
fix/organisation-store-guard-invalid-id
Draft

fix(organisations): don't fetch an organisation with a non-numeric id#8222
talissoncosta wants to merge 3 commits into
mainfrom
fix/organisation-store-guard-invalid-id

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Loading /getting-started locally ran two failed requests:

GET projects/?organisation=account   400  {"organisation":"Must be a valid integer."}
GET organisations/account/users/     500

Both come from one call, and the id is a literal string we send ourselves:

bootstrapOnboarding.ts    AppActions.refreshOrganisation()      // no id
app-actions.js            dispatches GET_ORGANISATION, id absent
organisation-store.js     getOrganisation(action.id || store.id)
organisation-store.js     id: 'account'                          // seed value

refreshOrganisation omits the id on purpose and leans on store.id, whose seed value is the string 'account'. Onboarding calls it before anything has populated that store, so 'account' goes out as the organisation id.

Three changes, smallest first:

  • refreshOrganisation takes an optional id. Callers that know it can pass it; the seven that don't behave exactly as before.
  • Onboarding passes the organisation it just resolved, so the refresh does what it was there to do rather than failing.
  • getOrganisation skips a non-numeric id, via a shared isNumericId. This is defence for the other unseeded-store callers: project-store calls refreshOrganisation four times, and EnvironmentAside and useUpdateProjectWithToast once each, none of which know an id.

isNumericId narrows its input before converting, because Number() coerces things that are not ids: a truthiness check let [], ['5'] and true through, and '0' passed while 0 did not. An id now has to be a positive integer, since these are serial primary keys.

The guard alone would only silence this. It needed the id fix as well, or onboarding's refresh would go from failing loudly to being skipped quietly, and the newly created project would not reach the org store.

Two things worth knowing:

  • The dev overlay makes this look local-only. It isn't: production runs the same two failed requests and renders an empty organisation view, which is harder to notice. The overlay reads [object Response] because _data rejects with the raw Response (_data.js:97), so it names nothing.
  • _data rejecting with an Error carrying status, URL and body is a worthwhile follow-up, and is why this took DevTools archaeology rather than reading a message.

Also in here, because the commit hook lints whole staged files and refused otherwise: a pre-existing nested ternary in the same file is unnested. It keeps the original comparison rather than localeCompare, which orders accents differently (ätest moves from last to second).

Touches bootstrapOnboarding.ts, which #8217 also changes. Different lines, so whichever merges second wants a rebase.

How did you test this code?

  • isNumericId unit tests (21), including 'account' itself, and a mutation check confirming six of them fail against the old implementation

  • test:unit (422) and typecheck clean

  • Verified the sort change is behaviour-identical, accented names included

  • Confirmed the seven remaining refreshOrganisation() callers pass no id, so they keep today's behaviour

  • /getting-started locally: no red overlay, and no organisation=account request in the network tab

  • The project onboarding creates appears in the project switcher without a reload

  • Organisation projects page still lists projects and members

  • Switching organisation still loads the new one's projects

@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview Aug 6, 2026 2:48am
flagsmith-frontend-staging Ready Ready Preview Aug 6, 2026 2:48am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 6, 2026 2:48am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 40509df8-f316-4e04-9806-81836471c20a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 436d5fec-84ae-43c3-9994-bf9d58c18395

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8978c and 80a5153.

📒 Files selected for processing (3)
  • frontend/common/stores/organisation-store.js
  • frontend/common/utils/__tests__/isNumericId.test.ts
  • frontend/common/utils/isNumericId.ts

Comment thread frontend/common/stores/organisation-store.js Outdated
Comment thread frontend/common/utils/isNumericId.ts Outdated
talissoncosta and others added 3 commits August 5, 2026 23:31
Loading the onboarding page locally showed a red dev overlay reading
`[object Response]`, with two failed requests behind it:

    GET projects/?organisation=account   400 {"organisation":"Must be a valid integer."}
    GET organisations/account/users/     500

Both fan out from one call, getOrganisation in organisation-store, which
validates nothing. The overlay is the same failure surfacing: _data rejects with
the raw Response, so an uncaught one prints as [object Response].

Guard it with a shared isNumericId, so a caller passing a route param or an
unloaded store value skips the request rather than triggering a 400, a 500 and an
unhandled rejection. In production the same call quietly yields an empty
organisation view, which is harder to notice than the overlay.

This is containment, not the root cause: something still passes the string
"account", and the request's initiator stack will name it.

Also unnests a pre-existing ternary in the same file, because the commit hook
lints whole staged files and refused the commit otherwise. Kept the original
comparison rather than localeCompare, which orders accents differently.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
refreshOrganisation dispatched GET_ORGANISATION without an id, so the
store fell back to its own, which starts as the string 'account'. Any
refresh before an organisation had been fetched sent that as the id.

The id is now optional on the action, so callers that know it can pass
it. Existing callers behave as before.
Number() turns values that are not ids into integers, so a truthiness
check let [], ['5'] and true through, and '0' passed while 0 did not.

The input is now narrowed to string or number, and an id must be a
positive integer, since these are serial primary keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant