Skip to content

Resource change request fires even when no changes are made #1452

Description

@Anchellon

Resource change request fires even when no changes are made

Description

When a user visits the resource edit page and clicks save without making
any changes, the frontend still fires POST /api/resources/{id}/change_requests
with an empty payload:

{"change_request": {}}

Steps to Reproduce

  1. Navigate to any resource edit page e.g. /organizations/1077/edit
  2. Do not change any fields
  3. Click Save
  4. Open browser DevTools → Network tab
  5. Observe POST /api/resources/{id}/change_requests fires with body:
    {"change_request": {}}

Root Cause

In app/pages/OrganizationEditPage.tsx, the save function compares each
resource field in state against the original API response to determine
if the resource was modified.

At line 1555, short_description is destructured from state:
const { short_description } = this.state;

At line 1572-1574, it is compared against the API response:
if (short_description !== resource.short_description) {
resourceChangeRequest.short_description = short_description;
resourceModified = true;
}

short_description has no input field on the edit page (line 860 declares
it as an optional state property but no onChange handler ever sets it),
so this.state.short_description is always undefined. However
resource.short_description returns a real string from the API for most
resources. This means:

undefined !== "some value from DB" → always true
→ resourceModified = true
→ request always fires

short_description itself never appears in the payload because
JSON.stringify silently drops undefined values, resulting in an empty
change_request object {}.

Expected Behaviour

POST /api/resources/{id}/change_requests should only fire when the user
has actually modified at least one resource field.

Actual Behaviour

The request fires on every save regardless of whether anything changed.

Impact

  • Unnecessary API calls on every save
  • Unnecessary change_requests rows inserted in the DB with no field_changes
  • Noise in the change request audit trail

Suggested Fix

Either:

  1. Remove the short_description comparison from the save function since
    there is no input field for it and it can never be changed via this page
  2. Or initialise this.state.short_description from the API response in
    handleAPIGetResource so the comparison is meaningful

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions