Fix Set-PnPDefaultColumnValues corrupting library defaults on invalid taxonomy values - #5412
Open
svermaak wants to merge 1 commit into
Open
Fix Set-PnPDefaultColumnValues corrupting library defaults on invalid taxonomy values#5412svermaak wants to merge 1 commit into
svermaak wants to merge 1 commit into
Conversation
… taxonomy values Unresolvable term values on taxonomy fields were silently dropped by GetDefaultColumnValueFromField, resulting in a malformed entry written to client_LocationBasedDefaults.html. From that point on every default column value operation on the library failed with 'Index was outside the bounds of the array', for any field type, until the file was deleted. Taxonomy values are now validated up front: each value must resolve to a term by id or by 'TermGroup|TermSet|Term' path, otherwise a clear error is thrown and nothing is written. Fixes pnp#5409
6 tasks
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.
Type of change
Related issue
Fixes #5409
What is in this Pull Request
When
Set-PnPDefaultColumnValuesis used on a managed metadata field with a value that cannot be resolved to a term (a bare label likeReproTerm, or a wrong path), the unresolvable value is silently dropped by PnP Framework'sGetDefaultColumnValueFromFieldand a malformed entry is written to the library'sForms/client_LocationBasedDefaults.html. From that moment on, every default column value operation on that library fails with "Index was outside the bounds of the array" - for any field, including plain text fields - because the framework's parser indexes into the malformed entry without bounds checks. The library stays broken until the defaults file is deleted.This PR validates taxonomy values up front in the cmdlet: each value must resolve to a term, either by term id or by full
TermGroup|TermSet|Termpath. If a value does not resolve, a clear error is thrown and nothing is written:Valid term ids and paths behave exactly as before.
Reproduction and verification
Reproduced and verified against a SharePoint Online test site with a document library containing a text column and a taxonomy column.
Before (v3.2.0): invalid value accepted silently, library defaults permanently broken
After (this fix): clear error, nothing written, library stays healthy, valid values still work
Workaround for already broken libraries
Deleting
<library>/Forms/client_LocationBasedDefaults.html(e.g. viaRemove-PnPFile) restores default column value functionality without recreating the library.Note: the unguarded parsing of existing entries lives in PnP Framework's
SetDefaultColumnValues/GetDefaultColumnValuesextensions; hardening that parser so a corrupted file recovers gracefully would be a follow-up in the pnpframework repo.