Sanitizing misidentifies diamond-shaped references as cycles
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 57/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- database
Research direction
Reproduce the diamond-shaped create case from the issue, then inspect the inner sanitize method within #sanitizeInitialValues. Verify that sanitizing shared records through both sibling paths leaves both author.profile and editor.profile defined.
Written by the indexing model from the issue text.
Description
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;
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 66
- Avg merge
- 9m
- Merged PRs (30d)
- 5
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mswjs/data
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
-
potentially resolved
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Non-nullable self-referencing relationsMay be free again @kettanaito claimed this 362 days ago, and no pull request is open. Open
Similar issues
-
bug HemiStake
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
hemilabs/ui-monorepo#2413 ·
Maintainers usually reply within 1 day
-
component/ui framework/react kind/bug language/javascript
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
meshery/meshery#22216 · 3 comments ·
Maintainers usually reply within 1 day
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
paperclipai/paperclip#14982 ·
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
lingdojo/kana-dojo#31515 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day