Fix/5109 debounce metadata field keystroke#5874
Open
shernandez-dev wants to merge 3 commits into
Open
Conversation
a17f984 to
f51c21b
Compare
Author
|
The failing test ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References
DsoEditMetadataValueComponent#ngOnChangesfires vocabulary requests on incomplete metadata fields, spamming 422 errors in dspace.log #5109Description
Debounces metadata field name input and gates
findDsoFieldVocabulary()behindvalidateMetadataField()to prevent 422 errors being triggered on every keystroke when editing item metadata.Instructions for Reviewers
Root Cause
DsoEditMetadataValueComponent#ngOnChangesreassignedfieldType$on every input change, immediately invokingfindDsoFieldVocabulary()with no debounce. TheisNotEmpty()guard inDsoEditMetadataFieldServicepassed for any non-empty string including partial inputs likedc.re, causingbyMetadataAndCollectionrequests that resulted in 422 errors. Since the 422 propagates through the full Spring Security filter chain before reaching the controller layer, no@ExceptionHandlercatches it — which is why the stack traces are so verbose.Reproduced and confirmed on DSpace 9.1, DSpace 10.0 and DSpace 11.0-SNAPSHOT.
List of changes
dso-edit-metadata-value.component.ts: MovedfieldType$initialization tongOnInitusing the existing_mdField$BehaviorSubject with a reactive pipeline:debounceTimeWorkaround(300)+distinctUntilChanged()+ regex guard +validateMetadataField()before callingfindDsoFieldVocabulary(). Replacedincludes('.')with the same regex guard inngOnChanges. Removed unusedgetFieldType()method.dso-edit-metadata-field.service.ts: AddedVALID_METADATA_FIELD_PATTERNregex as a defensive guard infindDsoFieldVocabulary(), rejecting inputs that don't matchschema.elementorschema.element.qualifierformat before making any HTTP request.dso-edit-metadata-value.component.spec.ts: Added 10 new unit tests for thefieldType$pipeline usingfakeAsync/tick(300), consistent with the project'sdebounceTimeWorkaroundtesting approach.Before
Typing
dc.contributor.author(20 chars) generated ~40 requests and thousands of log lines per session, e.g.:After
Typing
dc.contributor.authorgenerates exactly 1 request tobyMetadataAndCollection, fired only after the field is confirmed valid:How to Test
/items/{uuid}/edit/metadatadc.contributor.authorin the metadata field name input, pausing between keystrokesdocker logs -f dspace | grep -E "422|byMetadataAndCollection"Expected result: No 422 errors appear in the logs during typing. A single
byMetadataAndCollectionrequest fires only after the complete field name has been confirmed as valid.Checklist
mainbranchnpm run lintfails with a pre-existing error unrelated to this fix (src/themes/custom/eager-theme-components.ts). ESLint was run directly on the 3 modified files and passes without errors.npx madge --circularon the affected directory)