Skip to content

Conversation

@leoraba
Copy link
Contributor

@leoraba leoraba commented Nov 4, 2025

Description

This PR fixes and issue where creating a submission to edit data by systemId on the wrong entity does not return any error.

Code changes:

  • The Submission is now marked as INVALID when systemId does not exists in the right entity.
  • The submission includes in its response the systemId with empty values {} (means no data were found):
    Example:
"data": {
    "deletes": {},
    "inserts": {},
    "updates": {
      "diagnosis": [
        {
          "new": {},
          "old": {},
          "systemId": "1065Y2R2GWUHKD1U47E3V"
        },
        {
          "new": {},
          "old": {},
          "systemId": "DOESNOTEXIST"
        }
      ]
    }
  },
  • The submission includes in its response a list of errors to identify the records that are invalid:
    Example:
{
  "errors": {
    "updates": {
      "diagnosis": [
        {
          "index": 0,
          "reason": "UNRECOGNIZED_VALUE",
          "fieldName": "systemId",
          "fieldValue": "1065Y2R2GWUHKD1U47E3V"
        },
        {
          "index": 1,
          "reason": "UNRECOGNIZED_VALUE",
          "fieldName": "systemId",
          "fieldValue": "DOESNOTEXIST"
        }
      ]
    }
  }
}
  • Unit tests updated to include new functions added

Issue related:

Copy link
Contributor

@joneubank joneubank left a comment

Choose a reason for hiding this comment

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

Just check if we use the correct error type, the name of the one used seems confusing. Otherwise these changes look correct.

}

submissionSchemaErrors.updates[entityName].push(
createUnrecognizedFieldBatchError({
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the correct error name? The field systemId is recognized, but the value is not found for this entity. This is an invalid value, not unrecognized field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated code to return a INVALID_BY_RESTRICTION reason and an error object because Lectern does not provide a reason for 'INVALID_VALUE'.
Example:

{
  "fieldName": "systemId",
  "fieldValue": "ABC12456465",
  "reason": "INVALID_BY_RESTRICTION",
  "index": 0,
  "errors": [
    {
      "message": "Value does not match any existing record.",
      "restriction": {
        "rule": true,
        "type": "required"
      }
    }
  ],
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated code to return a UNRECOGNIZED_VALUE error.
Example:

{
          "index": 0,
          "reason": "UNRECOGNIZED_VALUE",
          "fieldName": "systemId",
          "fieldValue": "NOOOO"
        }

.references(() => dictionaries.id)
.notNull(),
errors: jsonb('errors').$type<Record<string, Record<string, DictionaryValidationRecordErrorDetails[]>>>(),
errors: jsonb('errors').$type<SubmissionErrors>(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a type used for Lyric submissions, it combines Lectern dictionary errors and additional validation errors

Comment on lines +451 to +456
const unrecodgnizedValueError: SubmissionRecordErrorDetails = {
fieldName: 'systemId',
fieldValue: submissionEditData.systemId,
index,
reason: 'UNRECOGNIZED_VALUE',
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

return a UNRECOGNIZED_VALUE submission error when the systemId doesn't match any record.

Comment on lines +618 to +629
if (foundSubmittedData.entityName !== schemaName) {
logger.error(
LOG_MODULE,
`Entity name mismatch for system ID '${systemId}': expected '${schemaName}', found '${foundSubmittedData.entityName}'`,
);
results.push({
systemId: systemId,
old: {},
new: {},
});
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

validation added to ensure the systemId belongs to the specified entityName.

if (!submissionSchemaErrors[actionType]) {
submissionSchemaErrors[actionType] = {};
}
if (dictionaryValidationError.reason !== 'INVALID_RECORDS') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function was refactored only, not related to any issue

@leoraba leoraba requested a review from joneubank November 19, 2025 20:14
Comment on lines +45 to +49
export type UnrecognizedValueReason = {
reason: 'UNRECOGNIZED_VALUE';
};

export type RecordErrorInvalidValue = FieldDetails & UnrecognizedValueReason;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@leoraba leoraba merged commit 23c631e into main Nov 19, 2025
2 checks passed
@leoraba leoraba deleted the fix/69-update-another-entity branch November 19, 2025 21:00
@leoraba leoraba mentioned this pull request Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants