Skip to content

fix: make nullable entity fields explicitly typed#380

Open
silent-cipher wants to merge 5 commits intomainfrom
fix/nullable-entity-types
Open

fix: make nullable entity fields explicitly typed#380
silent-cipher wants to merge 5 commits intomainfrom
fix/nullable-entity-types

Conversation

@silent-cipher
Copy link
Copy Markdown
Collaborator

closes #205

Copilot AI review requested due to automatic review settings March 19, 2026 11:41
@FilOzzy FilOzzy added this to FOC Mar 19, 2026
@github-project-automation github-project-automation bot moved this to 📌 Triage in FOC Mar 19, 2026
@silent-cipher silent-cipher self-assigned this Mar 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #205 by aligning TypeORM entity and related DTO/service code with the database reality that nullable columns can be null, reducing unsafe assumptions and runtime errors across metrics, jobs, deal flow, and IPNI logic.

Changes:

  • Update multiple TypeORM entities to type nullable columns as T | null (instead of non-null/optional).
  • Add/adjust null handling in metrics/services, deal flow metrics computations, and IPNI verification/monitoring.
  • Update selected DTOs to reflect nullable fields (e.g., provider/service URL).

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
apps/backend/src/metrics/services/providers.service.ts Avoids crashing when serviceTypes is null by using optional chaining.
apps/backend/src/metrics/services/failed-deals.service.ts Maps nullable dataset IDs to undefined for optional DTO fields.
apps/backend/src/metrics/dto/provider-performance.dto.ts Marks serviceUrl as nullable in DTO and Swagger schema.
apps/backend/src/metrics/dto/failed-retrievals.dto.ts Adjusts providerId typing to reflect DB nullability.
apps/backend/src/jobs/jobs.service.ts Normalizes nullable providerId to undefined where callers expect optional.
apps/backend/src/ipni/ipni-verification.service.ts Adds guard for missing service URL and tightens expected-provider construction input type.
apps/backend/src/dev-tools/dev-tools.service.ts Normalizes nullable deal fields in dev-tools responses and mappings.
apps/backend/src/deal/deal.service.ts Makes ingest/on-chain metric fields nullable; improves ingest latency/throughput computation guards and logging.
apps/backend/src/deal-addons/strategies/ipni.strategy.ts Adds explicit runtime failures for missing service URL / piece CID; switches entity import to type-only.
apps/backend/src/database/entities/storage-provider.entity.ts Types nullable providerId/serviceUrl as `T
apps/backend/src/database/entities/retrieval.entity.ts Types nullable retrieval columns as `T
apps/backend/src/database/entities/job-schedule-state.entity.ts Types lastRunAt as `Date
apps/backend/src/database/entities/deal.entity.ts Types many nullable deal columns as `T
apps/backend/src/common/logging.ts Allows pieceCid to be `string

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting review in FOC Mar 19, 2026
@BigLep BigLep requested a review from SgtPooki March 19, 2026 15:58
@BigLep BigLep added this to the M4.2: mainnet GA milestone Mar 19, 2026
Copy link
Copy Markdown
Collaborator

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

there are a lot of merge conflicts, and this PR has a lot of changes that i haven't got to look into deeply..

I would much rather see a smaller change since we're messing with metrics we're exporting

}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I haven't got a chance to look at this deeply

Comment on lines +193 to +201
dealLatencyMs: deal.dealLatencyMs ?? undefined,
dealLatencyWithIpniMs: deal.dealLatencyWithIpniMs ?? undefined,
ingestLatencyMs: deal.ingestLatencyMs ?? undefined,
ipniTimeToIndexMs: deal.ipniTimeToIndexMs ?? undefined,
ipniTimeToAdvertiseMs: deal.ipniTimeToAdvertiseMs ?? undefined,
ipniTimeToVerifyMs: deal.ipniTimeToVerifyMs ?? undefined,
serviceTypes: deal.serviceTypes ?? [],
spAddress: deal.spAddress,
errorMessage: deal.errorMessage,
errorMessage: deal.errorMessage ?? undefined,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i dont think the goal of this is to make things possible to be undefined.. we want them to be defined to have strict type awareness as much as possible, right?

if these were set to values before, adding a fallback to undefined is a regression isn't it?

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ⌨️ In Progress

Development

Successfully merging this pull request may close these issues.

Fix nullable entity types

5 participants