Skip to content

Fix Set-PnPDefaultColumnValues corrupting library defaults on invalid taxonomy values - #5412

Open
svermaak wants to merge 1 commit into
pnp:devfrom
svermaak:fix/set-defaultcolumnvalues-term-validation
Open

Fix Set-PnPDefaultColumnValues corrupting library defaults on invalid taxonomy values#5412
svermaak wants to merge 1 commit into
pnp:devfrom
svermaak:fix/set-defaultcolumnvalues-term-validation

Conversation

@svermaak

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix

Related issue

Fixes #5409

What is in this Pull Request

When Set-PnPDefaultColumnValues is used on a managed metadata field with a value that cannot be resolved to a term (a bare label like ReproTerm, or a wrong path), the unresolvable value is silently dropped by PnP Framework's GetDefaultColumnValueFromField and a malformed entry is written to the library's Forms/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|Term path. If a value does not resolve, a clear error is thrown and nothing is written:

Value 'ReproTerm' could not be resolved to a term. Provide a term id or the full path to the term in the format 'TermGroup|TermSet|Term'. The default column values on the list have not been changed.

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

Before the fix

After (this fix): clear error, nothing written, library stays healthy, valid values still work

After the fix

Workaround for already broken libraries

Deleting <library>/Forms/client_LocationBasedDefaults.html (e.g. via Remove-PnPFile) restores default column value functionality without recreating the library.

Note: the unguarded parsing of existing entries lives in PnP Framework's SetDefaultColumnValues/GetDefaultColumnValues extensions; hardening that parser so a corrupted file recovers gracefully would be a follow-up in the pnpframework repo.

… 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
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.

Set-PnPDefaultColumnValues Index was outside the bounds of the array

1 participant