Skip to content

DYN-10800: Reset stale TemplateFilePath to current install templates - #17309

Open
Chloepeg wants to merge 2 commits into
DynamoDS:masterfrom
Chloepeg:DYN-10800-Stale-TemplateFilePat--in-DynamoSettings.xml
Open

DYN-10800: Reset stale TemplateFilePath to current install templates#17309
Chloepeg wants to merge 2 commits into
DynamoDS:masterfrom
Chloepeg:DYN-10800-Stale-TemplateFilePat--in-DynamoSettings.xml

Conversation

@Chloepeg

@Chloepeg Chloepeg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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

10800 testing

Changes:

  • Revalidate TemplateFilePath on startup in InitializePreferenceLocations() and reset stale paths to PathManager.DefaultTemplatesDirectory
  • Treat missing/empty folders and previous-install templates<locale> paths as stale; preserve user-chosen custom folders that still contain .dyn files
  • Stop creating template directories in PathManager.UpdatePreferenceItemPath() so invalid persisted paths cannot be masked
  • Clear install-rooted TemplateFilePath during version migration in DynamoMigratorBase.MigrateFrom()
  • Add the resolved templates folder to trusted locations and persist the reset to DynamoSettings.xml
  • Add NUnit coverage in PathManagerTests and UserDataMigrationTests
  • Manual testing: Sandbox copy (Sandbox1/Sandbox2), custom template folder preserved, missing path in settings resets to current install templates.

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

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
@Chloepeg Chloepeg closed this Aug 24, 2026
@github-actions github-actions Bot changed the title Reset stale TemplateFilePath to current install templates DYN-10800: Reset stale TemplateFilePath to current install templates Aug 24, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-10800

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TemplateFilePath during DynamoModel.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.

Comment on lines +780 to +803
/// <summary>
/// True when the path looks like a Dynamo install's shipped templates folder
/// (…/templates/&lt;locale&gt;). 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;
}
}
Comment on lines +1928 to +1931
if (!string.Equals(persistedTemplatePath, PreferenceSettings.TemplateFilePath, StringComparison.OrdinalIgnoreCase))
{
PreferenceSettings.SaveInternal(pathManager.PreferenceFilePath);
}

@jasonstratton jasonstratton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment. Let me know if you would address it or not and when it is ready to merge. Thanks. ... Approving now

Comment thread src/DynamoCore/Models/DynamoModel.cs Outdated
}
}

var persistedTemplatePath = PreferenceSettings.TemplateFilePath;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@sonarqubecloud

Copy link
Copy Markdown

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.

3 participants