Skip to content

fix(dataset): make api fields optional and add guards to prevent null fields#2847

Open
belfhi wants to merge 2 commits into
SciCatProject:masterfrom
belfhi:datasetoutputDto-optional-fields
Open

fix(dataset): make api fields optional and add guards to prevent null fields#2847
belfhi wants to merge 2 commits into
SciCatProject:masterfrom
belfhi:datasetoutputDto-optional-fields

Conversation

@belfhi

@belfhi belfhi commented Jul 23, 2026

Copy link
Copy Markdown

fixes #2386

Description

Motivation

Fixes

  • Bug fixed (#X)

Changes:

  • changes made

Tests included

  • Included for each change/fix?
  • Passing?

Documentation

  • swagger documentation updated (required for API changes)
  • official documentation updated

official documentation info

Summary by Sourcery

Make dataset-related API response fields safer by allowing optional version metadata, preventing null array values, and improving include-parameter handling and relation loading.

Bug Fixes:

  • Avoid null-related errors in dataset lookup aggregation when relationships are missing.
  • Ensure include query parameters are correctly parsed when passed as comma-separated values from OpenAPI-generated clients.

Enhancements:

  • Treat API version fields on dataset, origdatablock, and sample output DTOs as optional metadata instead of required properties.
  • Normalize array-like dataset properties by filtering out null/undefined entries and defaulting schema arrays to empty lists.
  • Expose includable dataset relations (origdatablocks, datablocks, attachments, instruments, proposals, samples) as documented optional fields in the dataset output DTO.
  • Clarify OpenAPI definitions for include array parameters using form style with explode for dataset and origdatablock controllers.

added null check for attachments include to prevent http 400 for empty attachments.

add include fields to DTO

add defaults to fields to prevent null in API response.
@belfhi
belfhi requested a review from a team as a code owner July 23, 2026 09:10

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/common/utils.ts" line_range="1343-1350" />
<code_context>
   return keys.map((key) => decodeURIComponentExtended(key));
 }

+export function filterNullFromArray<T>(
+  value: (T | null | undefined)[] | undefined,
+): T[] | undefined {
+  if (!value) return undefined;
+  const filtered = value.filter(
+    (item): item is T => item !== null && item !== undefined,
+  );
+  return filtered.length > 0 ? filtered : undefined;
+}
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider whether converting empty arrays to `undefined` is desirable for DTO transformations

Because this helper returns `undefined` for empty arrays, DTO fields using `@Transform(({ value }) => filterNullFromArray<string>(value))` (e.g. `keywords`, `proposalIds`) will emit `undefined` instead of `[]` when stored arrays are empty. This changes the API surface and may break consumers that expect these properties to always exist (even when empty), especially given the new Mongoose defaults to `[]`. If callers rely on that stability, consider returning `filtered` even when empty.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/common/utils.ts Outdated
@belfhi belfhi changed the title fix(dataset): Make api fields optional and add guards to prevent null fields. fix(dataset): Make api fields optional and add guards to prevent null fields Jul 23, 2026
@belfhi belfhi changed the title fix(dataset): Make api fields optional and add guards to prevent null fields fix(dataset): make api fields optional and add guards to prevent null fields Jul 23, 2026
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.

no include variable like origdatablock returned in py sdk datasets v4

1 participant