Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Sanitizing misidentifies diamond-shaped references as cycles

オープン
#367 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
57/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript
領域
database

調査の方向性

issue にあるダイヤモンド形の create ケースを再現し、その後 #sanitizeInitialValues 内の内部 sanitize メソッドを調べます。両方の兄弟パスを通じて共有レコードをサニタイズした場合に、author.profile と editor.profile の両方が定義されたままになることを確認します。

索引モデルが issue の本文から書いたものです。

説明

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;
主要言語
TypeScript
スター
1.1k
フォーク
66
平均マージ
3分
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

mswjs/data のほかの issue

mswjs/data の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。