US-EPA-CAMD / easey-ui

Project Management repo for EPA Clean Air Markets Division (CAMD) Business Suite of applications
MIT License
0 stars 0 forks source link

Error Suppression: Can't Save Record when Location is Selected #6384

Open lgiannini1 opened 2 months ago

lgiannini1 commented 2 months ago

When trying to save a new error suppression record, the following error is generated if a location is selected from the dropdown.

Image

maxdiebold-erg commented 2 months ago

This is due to how TypeORM interprets and executes conditional logic in its find options: it is an open issue, although it hasn't yet been addressed as a bug in the package. In particular, the manifestation of this issue in ECMPS stems from applying an OR condition in the IsValidCodes validation pipe of the ErrorSuppressionPayloadDTO's locations attribute.

While it is possible to specify an OR condition when using TypeORM's find method, it appears that TypeORM first evaluates each side of the clause using an INNER JOIN when specifying nested relations.

There are at least two potential workarounds:

  1. use TypeORM's SelectQueryBuilder instead of the repository's find method
  2. execute two separate queries

Both workarounds require updating the IsValidCodes pipe. It is my opinion that option 2 is a better choice: the required changes are simpler and the queries can take advantage of parallelism to improve performance.

EDIT

After some reconsideration, I've decided to move forward with option 1 from the workarounds noted above. The IsValidCodes pipe compares the result count against the expected number of codes rather than just the presence of results, so there is a possibility that executing multiple queries could return more rows than a single joined query (although this would not be the case in any uses of the pipe in the current codebase).

Since this is an edge case, I think creating a separate, specialized pipe/validator is the safer solution, and it will prevent needlessly cluttering the IsValidCodes logic.

mxtomoto1 commented 2 months ago

Error Suppression was able to be created following above parameters without running into above error.

t_d1
bryanramirez1 commented 1 month ago

Verified in test environment - error suppression was successfully added without error message.