Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 65388a5

Browse files
mwillbanksymc9
andauthored
issue: rpc on update, 422 filtering error (#546)
* issue: rpc on update, 422 filtering error the error appears to be caused by the json filtering logic, it is attempting to utilize the filtering logic when there is an update on a list or json field even if there are no such values to be filtered during an update when attempting to set a new value * fix: rpc update handling * fix: undo the ORM side change since it's unrelated to the original issue * fix: get back the `args ?? {}` safety guard --------- Co-authored-by: ymc9 <104139426+ymc9@users.noreply.github.com>
1 parent be330ff commit 65388a5

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

packages/server/src/api/rpc/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,17 @@ export class RPCApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiH
221221
}
222222

223223
private async processRequestPayload(args: any) {
224-
const { meta, ...rest } = args;
224+
const { meta, ...rest } = args ?? {};
225225
if (meta?.serialization) {
226226
try {
227227
// superjson deserialization
228228
args = SuperJSON.deserialize({ json: rest, meta: meta.serialization });
229229
} catch (err) {
230230
return { result: undefined, error: `failed to deserialize request payload: ${(err as Error).message}` };
231231
}
232+
} else {
233+
// drop meta when no serialization info is present
234+
args = rest;
232235
}
233236
return { result: args, error: undefined };
234237
}

packages/server/test/api/rpc.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ describe('RPC API Handler Tests', () => {
365365
float Float
366366
decimal Decimal
367367
boolean Boolean
368+
stringList String[]
368369
bytes Bytes
369370
bars Bar[]
370371
}
@@ -386,6 +387,7 @@ describe('RPC API Handler Tests', () => {
386387
const dateValue = new Date();
387388
const bytesValue = new Uint8Array([1, 2, 3, 4]);
388389
const barBytesValue = new Uint8Array([7, 8, 9]);
390+
const stringListValue = ['a', 'b', 'c'];
389391

390392
const createData = {
391393
string: 'string',
@@ -396,6 +398,7 @@ describe('RPC API Handler Tests', () => {
396398
decimal: decimalValue,
397399
boolean: true,
398400
bytes: bytesValue,
401+
stringList: stringListValue,
399402
bars: {
400403
create: { bytes: barBytesValue },
401404
},
@@ -424,6 +427,8 @@ describe('RPC API Handler Tests', () => {
424427
expect(data.date instanceof Date).toBeTruthy();
425428
expect(Decimal.isDecimal(data.decimal)).toBeTruthy();
426429
expect(data.bars[0].bytes).toBeInstanceOf(Uint8Array);
430+
expect(Array.isArray(data.stringList)).toBeTruthy();
431+
expect(data.stringList).toEqual(stringListValue);
427432

428433
// find with filter not found
429434
const serializedQ = SuperJSON.serialize({
@@ -506,6 +511,27 @@ describe('RPC API Handler Tests', () => {
506511
});
507512
expect(r.status).toBe(200);
508513
expect(r.data).toBeNull();
514+
515+
// validate update on stringList
516+
const serializedUpdate = SuperJSON.serialize({
517+
where: { id: 1 },
518+
data: {
519+
stringList: ['d', 'e', 'f'],
520+
},
521+
});
522+
r = await handleRequest({
523+
method: 'patch',
524+
path: '/foo/update',
525+
query: {},
526+
client,
527+
requestBody: {
528+
...(serializedUpdate.json as any),
529+
meta: { serialization: serializedUpdate.meta },
530+
},
531+
});
532+
expect(r.status).toBe(200);
533+
expect(r.data).toBeTruthy();
534+
expect(r.data.stringList).toEqual(['d', 'e', 'f']);
509535
});
510536

511537
function makeHandler() {

0 commit comments

Comments
 (0)