Skip to content

fix(AppResources): default SpAppResource.description to name on creation#7985

Open
foozleface wants to merge 2 commits into
specify:mainfrom
calacademy-research:cas/fix-spappresource-null-description
Open

fix(AppResources): default SpAppResource.description to name on creation#7985
foozleface wants to merge 2 commits into
specify:mainfrom
calacademy-research:cas/fix-spappresource-null-description

Conversation

@foozleface

@foozleface foozleface commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

The "New Resource" flow in AppResources/Create.tsx constructs an SpAppResource without a description, so the row is persisted with Description = NULL. The backend report_runner create path already defaults description = name; this PR makes the frontend match.

Specify 6 hard-fails when opening a label whose underlying spappresource.Description is NULL, so any site still running S6 alongside S7 hits this immediately. Reported as Specify support ticket #824 — Grant confirmed the analysis and asked for a PR.

Changes

  • Extract buildNewAppResource() helper in Create.tsx; defaults description: name.trim()
  • Export the helper via exportsForTests (same pattern as getUrl in this file)
  • Add a unit test asserting the new resource has description === name.trim()

Note for sites running both S6 and S7

If you already have rows with Description IS NULL, S6 will still hard-fail on them after this PR is merged — this fix only prevents new NULL rows. A one-time backfill is safe and cheap (description is a simple text label, free-form):

-- Run once per Specify database; backfills any historic NULL descriptions
-- so Specify 6 stops crashing on labels created by Specify 7.
UPDATE spappresource SET Description = Name WHERE Description IS NULL;

Test plan

  • npx jest --testPathPattern CreateAppResource — 4/4 pass (3 existing + 1 new)
  • Manually create a new App Resource via User Tools → App Resources → New Resource and confirm spappresource.Description is non-NULL in the DB
  • Open the new resource as a label/report in Specify 6 and confirm it no longer crashes

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where creating app resources with empty descriptions could cause errors. The description field now defaults to the trimmed resource name.
  • Tests

    • Added tests to verify that app resource descriptions default correctly when not explicitly provided.

The frontend "New Resource" path constructed SpAppResource without a
description, persisting NULL. Specify 6 hard-fails when opening labels
backed by such rows. Mirror the backend report_runner behavior, which
already defaults description to name.

Refs ticket specify#824.

@Iwantexpresso Iwantexpresso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • npx jest --testPathPattern CreateAppResource — 4/4 pass (3 existing + 1 new)
  • Manually create a new App Resource via User Tools → App Resources → New Resource and confirm spappresource.Description is non-NULL in the DB
  • Open the new resource as a label/report in Specify 6 and confirm it no longer crashes

jest test results

Image

Whenever the resource created the description field for the spappresource is currently staying as null. I have tried with creating 3 different app resources so far. I am a little unsure how request changes would whirl for this pr but I assume it wouldn't hurt just placing this in as one for now

@github-project-automation github-project-automation Bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Apr 21, 2026
The previous commit defaulted description in Create.tsx, but that
resource is discarded: EditAppResource's onSaving returns false (per
specify#1596) and navigates to the editor URL, where EditorWrapper builds a
fresh skeleton from the URL params. That skeleton had no description,
so spappresource.Description was still persisted as NULL — as observed
in review testing.

Move the default into the EditorWrapper skeleton (newAppResourceSkeleton)
so the record that is actually saved carries description = name. Applies
to both SpAppResource and SpViewSetObj, which both have the column.

Refs ticket specify#824.
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7436838a-403e-4e5b-b346-d0723c94680c

📥 Commits

Reviewing files that changed from the base of the PR and between a0f96a8 and 5cfaccc.

📒 Files selected for processing (3)
  • specifyweb/frontend/js_src/lib/components/AppResources/Create.tsx
  • specifyweb/frontend/js_src/lib/components/AppResources/EditorWrapper.tsx
  • specifyweb/frontend/js_src/lib/components/AppResources/__tests__/CreateAppResource.test.tsx

📝 Walkthrough

Walkthrough

This PR refactors description-defaulting logic for app resources into two reusable helper functions: buildNewAppResource in Create.tsx and newAppResourceSkeleton in EditorWrapper.tsx. Both helpers automatically set description to the trimmed resource name to handle null-description constraints. New unit tests verify this behavior across both helpers.

Changes

App Resource Description Defaulting

Layer / File(s) Summary
Create.tsx: buildNewAppResource helper
specifyweb/frontend/js_src/lib/components/AppResources/Create.tsx
EditAppResource refactors its useMemo to call new buildNewAppResource(type, name, mimeType, directory) helper instead of inlining resource construction. The helper constructs the resource via deserializeResource(addMissingFields(...)) and now sets description: name.trim() alongside other required fields. Helper is exported via exportsForTests for testing.
EditorWrapper.tsx: newAppResourceSkeleton helper
specifyweb/frontend/js_src/lib/components/AppResources/EditorWrapper.tsx
Introduces newAppResourceSkeleton(mode, name, mimeType) to build a SerializedResource<SpAppResource> with name and description both defaulted to the trimmed name (or empty string). Wrapper component's useMemo now calls this helper instead of inlining the addMissingFields object construction. Helper is exported via exportsForTests.
Tests: Description defaulting behavior
specifyweb/frontend/js_src/lib/components/AppResources/__tests__/CreateAppResource.test.tsx
Adds new test imports for buildNewAppResource and newAppResourceSkeleton, plus resource type constants. New describe blocks add unit tests asserting that both helpers automatically default description to the trimmed provided label, with additional coverage for "view sets" and undefined mimeType cases.
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Testing Instructions ⚠️ Warning PR objectives claim "(4/4)" tests passed but file contains 6 tests; no manual testing instructions provided despite noting manual DB verification and cross-version testing remain unchecked. Add clear testing instructions documenting: (1) how to run unit tests; (2) manual steps for DB verification; (3) cross-version testing procedures; correct "(4/4)" discrepancy with actual test count of 6.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: defaulting SpAppResource.description to name on creation, which directly aligns with the PR's primary objective of fixing issue #824.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Automatic Tests ✅ Passed PR includes appropriate automatic tests: unit tests for buildNewAppResource and newAppResourceSkeleton covering the description-defaulting behavior required by ticket #824.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@foozleface

Copy link
Copy Markdown
Collaborator Author

Good catch — description was indeed still NULL. Root cause: the resource built in Create.tsx is never the one that gets saved. EditAppResource's onSaving returns false (intentional, per #1596) and just navigates to the editor URL; EditorWrapper then builds a fresh skeleton from the URL params, and that skeleton — which had no description — is what AppResourceEditor actually persists.

5cfaccc moves the default onto that skeleton (newAppResourceSkeleton), so the saved record now carries description = name for both SpAppResource and SpViewSetObj, with tests covering the skeleton path. Could you re-test via User Tools → App Resources → New Resource? spappresource.Description should now match the resource name.

@foozleface foozleface requested a review from Iwantexpresso June 10, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Dev Attention Needed

Development

Successfully merging this pull request may close these issues.

2 participants