-
Notifications
You must be signed in to change notification settings - Fork 2
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
Unexpected 500 response: "...values and fields must be sorted..." #381
Comments
The running version is In Promise.all([
db.sql('proposalFieldValues.selectByProposalId', { proposalId: req.params.id }),
db.sql('applicationFormFields.selectByProposalId', { proposalId: req.params.id }),
db.sql('proposalVersions.selectByProposalId', { proposalId: req.params.id }),
]).then(([
//...
const valuesWithFields = joinApplicationFormFieldsToProposalFieldValues(
proposalFieldValuesQueryResult.rows,
applicationFormFieldsQueryResult.rows,
); The join function does some consistency/assumption checks before joining: export const joinApplicationFormFieldsToProposalFieldValues = (
values: ProposalFieldValue[],
fields: ApplicationFormField[],
): ProposalFieldValue[] => {
const newValues = structuredClone(values);
if (newValues.length !== fields.length) {
// It is invalid to try to zip values and fields of unequal length.
throw new Error(`Given arrays must be of equal length. ${values.length} !== ${fields.length}`);
}
return newValues.map((value, index) => {
// Look in the fields array at the same index as the values array.
const field = fields[index];
if (field === undefined) {
throw new Error(
`Expected only defined fields and values, copiedFields[${index}] was undefined`,
);
}
if (value.applicationFormFieldId !== field.id) {
throw new Error(
`Given values and fields must be sorted such that they correspond. index=${index}: ${value.applicationFormFieldId} !== ${field.id}.`,
);
}
// When all is well, add the field to the value.
return { ...value, applicationFormField: field };
});
}; The queries ( The length of the two query result sets is identical or we would have gotten I ran the queries manually and am comparing the results. Indeed the 88th and 89th (of 90) rows order is flipped. The proposal field value After dump and restore locally, the issue does not appear locally, which is not entirely unexpected because the issue only appeared after some time and the order if not explicit can be non-deterministic. |
Without this change, a non-deterministic sort order can cause an HTTP 500 response with message "...values and fields must be sorted...". With this change, the sort order is first by position (as before) and then also by proposal field value (pfv) ID because there can be many pfv rows for a given application form field (aff) row. This should be sufficient to guarantee deterministic order such that the application join will succeed. Issue #381 Unexpected 500 response: "values and fields must be sorted" See also #198 and #210.
Without this change, a non-deterministic sort order can cause an HTTP 500 response with message "...values and fields must be sorted...". With this change, the sort order is first by position (as before) and then also by proposal field value (pfv) ID because there can be many pfv rows for a given application form field (aff) row. This should be sufficient to guarantee deterministic order such that the application join will succeed. Issue #381 Unexpected 500 response: "values and fields must be sorted" See also #198 and #210.
It appears to have fixed the issue in prod. |
This URL currently returns a 500: https://api.philanthropydatacommons.org/proposals/452?includeFieldsAndValues=true
The text was updated successfully, but these errors were encountered: