Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Sanitizing misidentifies diamond-shaped references as cycles

Aperta
#367 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
database

Direzione di ricerca

Riproduci il caso di creazione a forma di diamante dell'issue, quindi esamina il metodo sanitize interno all'interno di #sanitizeInitialValues. Verifica che la sanitizzazione dei record condivisi attraverso entrambi i percorsi fratelli lasci definiti sia author.profile sia editor.profile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

This is a very similar issue to #348, but occurs when the same record is referenced from two different paths in a create call.

For example, this code results in the same type of validation error as #348:

import { Collection } from '@msw/data';
import * as v from 'valibot';

const profileSchema = v.object({
  id: v.string(),
  bio: v.string(),
});

const userSchema = v.object({
  id: v.string(),
  name: v.string(),
  get profile() { return profileSchema; },
});

const postSchema = v.object({
  id: v.string(),
  title: v.string(),
  get author() { return userSchema; },
  get editor() { return userSchema; },
});

const profiles = new Collection({ schema: profileSchema });
const users = new Collection({ schema: userSchema });
const posts = new Collection({ schema: postSchema });

users.defineRelations({ one }) => ({ profile: one(profiles) }));
posts.defineRelations({ one }) => ({
  author: one(users),
  editor: one(users),
}));

const profile = await profiles.create({ id: 'p1', bio: 'hi' });
const user = await users.create({ id: 'u1', name: 'Alice', profile });

// Diamond: same user referenced from two sibling fields
await posts.create({
  id: 'post1',
  title: 'Hello',
  author: user,
  editor: user,
});

In this setup, either author.profile or editor.profile will be undefined after sanitization.

From my testing, I've been able to fix the error by adding the following to the inner sanitize method within the #sanitizeInitialValues method:

const result = Object.fromEntries(...);

if (record && !isRevisit) {
  visited.delete(record[kPrimaryKey]);
}

return result;
Lingua principale
TypeScript
Stelle
1.1k
Fork
66
Merge medio
3m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di mswjs/data

Tutte le issue di mswjs/data

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.