Skip to content

fix: disallow undefined where clause #21062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

fix: disallow undefined where clause #21062

wants to merge 7 commits into from

Conversation

anikdhabal
Copy link
Contributor

@anikdhabal anikdhabal commented May 1, 2025

What does this PR do?

Summary by mrge

Disallowed undefined, empty object, and empty array values in Prisma where clauses to prevent invalid queries.

  • Bug Fixes
    • Added validation to throw errors if a where clause is undefined, empty, or contains undefined fields.
    • Updated extension to cover findMany, updateMany, and deleteMany queries.

@anikdhabal anikdhabal requested a review from a team as a code owner May 1, 2025 17:19
Copy link

vercel bot commented May 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview May 1, 2025 6:01pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview May 1, 2025 6:01pm

@graphite-app graphite-app bot requested a review from a team May 1, 2025 17:19
@keithwillcode keithwillcode added the core area: core, team members only label May 1, 2025
Copy link

graphite-app bot commented May 1, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (05/01/25)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link

@mrge-io mrge-io bot left a comment

Choose a reason for hiding this comment

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

mrge found 1 issue across 3 files. View it in mrge.io

Comment on lines 45 to 56
$allModels: {
async deleteMany({ args, query }) {
checkUndefinedInValue(args.where);
validateWhereClause(args.where);
return query(args);
},
async updateMany({ args, query }) {
checkUndefinedInValue(args.where);
validateWhereClause(args.where);
return query(args);
},
async findMany({ args, query }) {
validateWhereClause(args.where);
return query(args);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we have this guard for these operations. Do we need to add more operations here?

Comment on lines +62 to +91
it("validateWhereClause should throw exception when the where object is undefined", async () => {
const where = undefined;

expect(() => validateWhereClause(where)).toThrowError('The "where" clause cannot be undefined.');
});

it("validateWhereClause should throw exception when the where object is {}", async () => {
const where = {};

expect(() => validateWhereClause(where)).toThrowError('The "where" clause cannot be an empty object {}.');
});

it("validateWhereClause should throw exception when the where object is []", async () => {
const where = [];

expect(() => validateWhereClause(where)).toThrowError('The "where" clause cannot be an empty array [].');
});

it("validateWhereClause should throw exception when the 'in' field of where object is []", async () => {
const where = {
id: {
in: [],
},
};

expect(() => validateWhereClause(where)).toThrowError(
'The "in" value for the field "id" cannot be an empty array [].'
);
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new test

Copy link
Contributor

github-actions bot commented May 2, 2025

E2E results are ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants