Skip to content
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

OData $filter: unsupported function results in 500 error #957

Open
matthew-white opened this issue Aug 21, 2023 · 0 comments
Open

OData $filter: unsupported function results in 500 error #957

matthew-white opened this issue Aug 21, 2023 · 0 comments
Labels

Comments

@matthew-white
Copy link
Member

A user on v2023.3.1 tried to use contains() in the OData $filter query parameter, which resulted in an error in Sentry. We don't support the OData contains() function, which causes methodCall() in odata-filter.js to return undefined, then I think odataFilter() as a whole to return undefined:

const methodCall = (fn, params) => {
// n.b. odata-v4-parser appears to already validate function name and arity.
const lowerName = fn.toLowerCase();
if (extractFunctions.includes(lowerName))
return sql`extract(${raw(lowerName)} from ${op(params[0])})`; // eslint-disable-line no-use-before-define
else if (fn === 'now')
return sql`now()`;
};

Slonik then throws an error about passing undefined to a sql`` template string:

InvalidInputError: SQL tag cannot be bound an undefined value.
  File "/usr/odk/node_modules/slonik/dist/src/factories/createSqlTag.js", line 27, col 19, in sql
    throw new errors_1.InvalidInputError('SQL tag cannot be bound an undefined value.');
  File "/usr/odk/lib/model/query/submissions.js", line 309, col 13, in _export
    return sql`
  File "/usr/odk/lib/model/query/submissions.js", line 348, col 10, in <anonymous>
    stream(_export(formId, draft, keyIds, options))
  File "/usr/odk/lib/model/container.js", line 30, col 33, in Object.module.<computed> [as streamForExport]
    const result = fn(...args)(container);
  File "/usr/odk/lib/resources/odata.js", line 68, col 25, in <anonymous>
    Submissions.streamForExport(form.id, draft, undefined, options),
  File "/usr/odk/node_modules/slonik/dist/src/factories/createSqlTag.js", in runMicrotasks
  File "node:internal/process/task_queues", line 96, col 5, in processTicksAndRejections

Instead of returning undefined, I think odataFilter() should throw an OData-related Problem if passed a function that it doesn't support. We throw a Problem in other cases in which we aren't able to handle the filter expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant