DYN-10800: Reset stale TemplateFilePath to current install templates - #17309
DYN-10800: Reset stale TemplateFilePath to current install templates#17309Chloepeg wants to merge 2 commits into
Conversation
Persisted TemplateFilePath was an absolute install path that was never revalidated. After copying Sandbox to a new folder or upgrading, Dynamo kept the old path or recreated it as an empty folder. - Revalidate TemplateFilePath on startup and reset to DefaultTemplatesDirectory when stale - Stop creating template folders in UpdatePreferenceItemPath - Clear install-rooted TemplateFilePath during version migration - Trust the resolved templates folder and save the reset to DynamoSettings.xml - Add unit tests
There was a problem hiding this comment.
See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-10800
There was a problem hiding this comment.
Pull request overview
This PR fixes a long-standing issue where PreferenceSettings.TemplateFilePath could remain stuck pointing at a previous Dynamo/Sandbox install location (or be recreated as an empty folder), causing Home screen Templates and “File > New > From Template” to appear empty or resolve to the wrong folder. It introduces startup-time revalidation, migration-time cleanup, and NUnit coverage to ensure stale paths are reset to the current install’s default templates directory while valid user-custom template folders are preserved.
Changes:
- Revalidate
TemplateFilePathduringDynamoModel.InitializePreferenceLocations()and persist resets when a stale path is detected. - Reset install-shaped or invalid template paths during version migration (
DynamoMigratorBase.MigrateFrom()). - Update
PathManager.UpdatePreferenceItemPath()behavior for Templates to avoid masking invalid persisted paths by creating directories, with new NUnit tests for these scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/DynamoCoreTests/UserDataMigrationTests.cs | Adds migration tests ensuring stale install-rooted/invalid template paths are cleared while valid custom template folders are preserved. |
| test/DynamoCoreTests/Configuration/PathManagerTests.cs | Adds startup/path manager tests verifying stale/missing/empty template paths reset to defaults and are persisted. |
| src/DynamoCore/Models/DynamoModel.cs | Adds startup-time revalidation/reset of the persisted template path, updates trusted locations, and persists resets. |
| src/DynamoCore/Core/DynamoMigrator.cs | Clears stale/invalid or install-shaped template paths during migration to avoid carrying forward wrong install-rooted locations. |
| src/DynamoCore/Configuration/PathManager.cs | Adds helpers to detect valid template directories and stale install-shaped paths, and changes Templates preference path updates to avoid auto-creating directories. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /// <summary> | ||
| /// True when the path looks like a Dynamo install's shipped templates folder | ||
| /// (…/templates/<locale>). User-chosen custom folders do not match this shape. | ||
| /// </summary> | ||
| internal static bool IsInstallRootedTemplatesDirectory(string directoryPath) | ||
| { | ||
| if (string.IsNullOrEmpty(directoryPath)) | ||
| return false; | ||
|
|
||
| try | ||
| { | ||
| var trimmed = directoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); | ||
| var locale = Path.GetFileName(trimmed); | ||
| if (!Configurations.SupportedLocaleDic.Values.Contains(locale)) | ||
| return false; | ||
|
|
||
| var templatesFolderName = Path.GetFileName(Path.GetDirectoryName(trimmed)); | ||
| return string.Equals(templatesFolderName, Configurations.TemplatesAsString, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
| catch (ArgumentException) | ||
| { | ||
| return false; | ||
| } | ||
| } |
| if (!string.Equals(persistedTemplatePath, PreferenceSettings.TemplateFilePath, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| PreferenceSettings.SaveInternal(pathManager.PreferenceFilePath); | ||
| } |
jasonstratton
left a comment
There was a problem hiding this comment.
Just one minor comment. Let me know if you would address it or not and when it is ready to merge. Thanks. ... Approving now
| } | ||
| } | ||
|
|
||
| var persistedTemplatePath = PreferenceSettings.TemplateFilePath; |
There was a problem hiding this comment.
persistedTemplatePath is captured after the pre-existing locale-swapped (lines 1896–1908) so the log message ("Configured template path X is not available...") will log the local swapped value instead of that is in DynamoSettings.xml ... maybe that's the intent, but worth pointing out.
There was a problem hiding this comment.
I moved the capture before the locale swap so the log reflects the value from DynamoSettings.xml. Ready to merge.
Move persistedTemplatePath capture before the locale Replace so the fallback log reports the value from DynamoSettings.xml, not the locale-swapped path.
|



This PR addresses DYN-10800.
This updates the persisted TemplateFilePath in DynamoSettings.xml was an absolute install path that was never revalidated. After copying Sandbox to a new folder or upgrading, Dynamo kept the old path (or recreated it as an empty folder), so the Home screen Templates section was empty and File - New - From Template opened the wrong location.
Manual testing: Launched Sandbox 1 → Home Templates and preference path used Sandbox 1\Debug\templates\en-US.
Closed Dynamo, launched Sandbox 2 → path updated to Sandbox 2\Debug\templates\en-US (settings no longer stuck on Sandbox 1).
Changes:
Declarations
Check these if you believe they are true
Release Notes
Fixed an issue where Home screen Templates and File - New - From Template could be empty or point to the wrong folder after moving Sandbox to a new location or upgrading Dynamo, when a stale template path was saved in settings.
Reviewers
@zeusongit
@DynamoDS/eidos
FYIs
@dnenov
@johnpierson
@jnealb
@jasonstratton