Skip to content

Guard getResourceStatuses against a null resource#2566

Open
Valyrian-Code wants to merge 1 commit into
GeoNode:masterfrom
Valyrian-Code:fix/resource-statuses-null-guard
Open

Guard getResourceStatuses against a null resource#2566
Valyrian-Code wants to merge 1 commit into
GeoNode:masterfrom
Valyrian-Code:fix/resource-statuses-null-guard

Conversation

@Valyrian-Code

Copy link
Copy Markdown

Problem

getResourceStatuses(resource, userInfo) in utils/ResourceUtils.js is written to tolerate a missing resource — it guards three reads:

const { executions = [] } = resource || {};
const isApproved = resource?.is_approved;
const isPublished = isApproved && resource?.is_published;

…but then dereferences resource without a guard:

...(resource.advertised === false ? [{ ... }] : []),

So getResourceStatuses(null) (or undefined) throws TypeError: Cannot read properties of null (reading 'advertised'), defeating the null-handling the rest of the function already implements.

Fix

...(resource?.advertised === false ? [{ ... }] : []),

Test

Added to utils/__tests__/ResourceUtils-test.js: getResourceStatuses(null) throws on master and returns the expected status object (isProcessing/isDeleting/isCopying: false, items: []) with the fix. Full suite green.

getResourceStatuses already tolerates a missing resource (const {executions=[]}
= resource || {}, resource?.is_approved, resource?.is_published) but then
dereferenced resource.advertised directly, throwing TypeError on null. Use
resource?.advertised to complete the existing null handling.

Adds a test in ResourceUtils-test.js; getResourceStatuses(null) throws on
master and returns the expected status object with the fix.
Copilot AI review requested due to automatic review settings June 11, 2026 19:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces optional chaining (resource?.advertised) in the getResourceStatuses utility function to prevent potential runtime errors when the resource parameter is null or undefined. Additionally, a unit test has been added to verify that the function handles a null resource gracefully and returns the expected default statuses. There are no review comments to address, and the changes look correct and well-tested.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants