Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/__tests__/normalizeSingularRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ describe('normalizeSingularRequest', () => {
const out = normalizeSingularRequest('GET', complex, model);
expect(out).toBe(complex);
});

it('allows GET requests with only pagination', () => {
const model = makeModel('actor', ['actor_id']);
const req = { [C6C.PAGINATION]: { LIMIT: 100, PAGE: 1 } } as any;
const out = normalizeSingularRequest('GET', req, model);
expect(out).toBe(req);
});

it('allows empty GET requests', () => {
const model = makeModel('actor', ['actor_id']);
const req = {} as any;
const out = normalizeSingularRequest('GET', req, model);
expect(out).toBe(req);
});
});
7 changes: 7 additions & 0 deletions src/api/utils/normalizeSingularRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export function normalizeSingularRequest<
const hasComplexKeys = keys.some(k => k !== C6C.PAGINATION && specialKeys.has(k));
if (hasComplexKeys) return request; // already complex

// For GET requests, if there are no non-special keys (e.g., only PAGINATION),
// treat it as a multi-row request and leave it unchanged.
if (requestMethod === C6C.GET) {
const hasNonSpecialKeys = keys.some(k => !specialKeys.has(k));
if (!hasNonSpecialKeys) return request;
Comment on lines +36 to +40

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] Skip path primary keys when request is otherwise empty

The new early return for GET requests that contain only special keys runs before the removedPrimary parameter is applied, so calling normalizeSingularRequest('GET', {}, model, { key: 'actor_id', value: 5 }) now returns {} instead of reconstructing WHERE: { actor_id: 5 }. HttpExecutor routinely strips the primary key from the query and passes it via removedPrimaryKV; under this change, singular GETs whose PK was moved into the URL (with or without pagination) will bypass PK validation and normalization, which can cause the request to be treated as a multi-row fetch and skip cache keying/SQL generation for the intended row.

Useful? React with 👍 / 👎.

}

// We treat it as singular when it's not complex.
// For GET, PUT, DELETE only
if (!(requestMethod === C6C.GET || requestMethod === C6C.PUT || requestMethod === C6C.DELETE)) {
Expand Down