Skip to content

fix(record): remove Number() coercion in reload and destroyRecord to support string ids#246

Merged
michaeljymsgutierrez merged 2 commits into
developfrom
fix/string-id-support-reload-destroy-record
Jul 2, 2026
Merged

fix(record): remove Number() coercion in reload and destroyRecord to support string ids#246
michaeljymsgutierrez merged 2 commits into
developfrom
fix/string-id-support-reload-destroy-record

Conversation

@michaeljymsgutierrez

Copy link
Copy Markdown
Owner

Description

record.reload() and record.destroyRecord() were calling Number() on the record ID before passing it to the internal _request() method. For numeric IDs this was harmless, but for string IDs like JO-26181S4VPU65, Number() returns NaN, causing the request URL to become /api/v1/resource/NaN instead of /api/v1/resource/JO-26181S4VPU65.

This fix removes the Number() coercion from both _reloadRecord and _deleteRecord, passing the ID as-is - consistent with how _saveRecord and findRecord already handle IDs. The internal _request() method already supports both number and string IDs via isNumber(resourceId) || isString(resourceId).

Github Issue: N/A

Changes

  • packages/src/lib/api-resource-manager.js - removed Number() coercion from _reloadRecord (line 740) and _deleteRecord (line 718); both now pass getProperty(currentRecord, 'id') directly as resourceId
  • packages/tests/units/record.js - added two new tests: "Verify reload with string collection record id" and "Verify destroyRecord with string collection record id"
  • packages/tests/mirage/index.js - updated DELETE /addresses/:id handler to echo back a record with the matching string ID when a non-numeric ID is provided, enabling proper unload assertion in the destroyRecord test
  • packages/dist/arm-js-library.js - rebuilt distribution file reflecting the source fix

Screenshots/Images

N/A - no UI changes.

How Has This Been Tested?

  • Unit tests: 2 new tests added covering reload and destroyRecord with string IDs - both pass
  • Full suite: All 83 tests pass (yarn test)
  • Coverage verified: Audited all ID-handling paths in the library - no other Number() or parseInt coercions remain; _saveRecord, findRecord, peekRecord, and _getCollectionRecord all already handle string IDs correctly

Checklist

  • Code follows the project's coding standards and best practices.
  • Tests are written for new functionality and existing tests pass.
  • Documentation is updated to reflect changes.
  • The PR is assigned to the correct reviewers.

Reviewer Guidance

  • The fix is minimal - only 2 lines changed in api-resource-manager.js (the Number() wrappers in _reloadRecord and _deleteRecord)
  • _saveRecord was already correct and did not need changes - it uses uuidValidate() to distinguish new records (UUID) from existing ones (any non-UUID ID), then passes the ID as-is
  • The Mirage DELETE handler update is test-only - it now returns the correct record shape when a non-numeric ID is used, so unloadRecord can find and remove the right record by hashId

@michaeljymsgutierrez michaeljymsgutierrez self-assigned this Jul 2, 2026
@michaeljymsgutierrez michaeljymsgutierrez added the bug Confirmed bugs and reported issues label Jul 2, 2026
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
arm-js-library-demo Ready Ready Preview, Comment Jul 2, 2026 1:22am

@michaeljymsgutierrez michaeljymsgutierrez merged commit e1eb16b into develop Jul 2, 2026
3 checks passed
@michaeljymsgutierrez michaeljymsgutierrez deleted the fix/string-id-support-reload-destroy-record branch July 2, 2026 01:24
michaeljymsgutierrez added a commit that referenced this pull request Jul 2, 2026
- [e2a8700][michaeljymsgutierrez]: Updated release version from v2.9.1 to v2.9.2 - 2026-07-02 09:29:18
- [e1eb16b][Chael Gutierrez]: fix(record): remove Number() coercion in reload and destroyRecord to support string ids (#246) - 2026-07-02 09:24:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Confirmed bugs and reported issues

Projects

Development

Successfully merging this pull request may close these issues.

1 participant