Skip to content

Fix Regressions cause by Copilot Auto Fix#3259

Merged
jmcouffin merged 4 commits intodevelopfrom
tay0thman-Fix-Regressions-cause-by-Copilot-Auto-Fix
Apr 4, 2026
Merged

Fix Regressions cause by Copilot Auto Fix#3259
jmcouffin merged 4 commits intodevelopfrom
tay0thman-Fix-Regressions-cause-by-Copilot-Auto-Fix

Conversation

@tay0thman
Copy link
Copy Markdown
Contributor

Copilot Hallucinated when Auto fixed previous PR,

Five changes from the merged version:

_ensure_path_registered() line 59 — Replaced user_config.thirdparty_ext_root_dirs (doesn't exist) with user_config.core.get_option(CONSTS.ConfigsUserExtensionsKey, ...) which reads the raw config without filtering by op.exists()
init() line 174 — _get_default_ext_dir() instead of raw [0]
_update_add_custom_section_for_new() line 430 — same
install_custom_extension() catalog path, line 490 — same
install_custom_extension() Git URL path, line 542 — same

@tay0thman
Copy link
Copy Markdown
Contributor Author

@devloai Please review and report back.

Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

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

Review Summary

The five regressions described in the PR description are correctly identified and the fixes look sound overall:

  • _ensure_path_registered() — correctly replaces the hallucinated user_config.thirdparty_ext_root_dirs attribute with a direct user_config.core.get_option(CONSTS.ConfigsUserExtensionsKey, ...) call. The exception scope is appropriately broadened to except Exception.
  • __init__(), _update_add_custom_section_for_new(), and both paths in install_custom_extension() — correctly replace the index-zero-access pattern get_thirdparty_ext_root_dirs(include_default=True)[0] with _get_default_ext_dir(), which is safe against an empty list.
  • _get_default_ext_dir() itself is a clean, defensive helper with a proper fallback to THIRDPARTY_EXTENSIONS_DEFAULT_DIR.

One issue found — see inline comment. The read-side fix in _ensure_path_registered correctly preserves offline paths, but the write-back on line 71 calls set_thirdparty_ext_root_dirs(), which raises PyRevitException for any path that doesn't exist on disk — effectively undoing the benefit of the raw-read for users with offline network shares.

Suggestions

  • Fix write-back in _ensure_path_registered to bypass existence check for offline paths Apply

Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

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

PR Summary:

This PR fixes regressions introduced by a Copilot Auto Fix in a prior PR. The five corrections replace non-existent user_config.thirdparty_ext_root_dirs references with core.get_option(CONSTS.ConfigsUserExtensionsKey, ...), and replace direct [0] indexing of get_thirdparty_ext_root_dirs() results with a safe helper _get_default_ext_dir().

Review Summary:

The mechanical fixes are correct — the hallucinated attribute is gone and the index-without-bounds-check is gone. However, there is a logical contradiction in _ensure_path_registered: the raw config is read via core.get_option specifically to preserve offline network shares, but the write-back goes through set_thirdparty_ext_root_dirs(), which raises PyRevitException for any path that doesn't currently exist on disk (userconfig.py:750-752). This completely undoes the offline-preservation intent — if an offline share is in the list, the new path registration fails entirely. The fix is to write back symmetrically via user_config.core.set_option(CONSTS.ConfigsUserExtensionsKey, raw_dirs). There's also a silent except Exception: with no logging on the fallback path, which hides read failures from diagnostics.

Suggestions

  • Update _ensure_path_registered write-back to use user_config.core.set_option(CONSTS.ConfigsUserExtensionsKey, raw_dirs) directly, matching the core.get_option read and preserving offline paths end-to-end. Apply

Apply all quick fixes (2 quick fixes)

devloai bot added 2 commits April 3, 2026 21:18
Use core.set_option() instead of set_thirdparty_ext_root_dirs() when registering
extension paths. This avoids the existence check in set_thirdparty_ext_root_dirs()
which would fail for temporarily-offline network shares, defeating the purpose of
reading the raw list.

Fixes the issue identified in review: set_thirdparty_ext_root_dirs() raises
PyRevitException for any path that doesn't currently exist on disk.
…egistered

- Move CONSTS import outside try block so it's available for both the
  read and write paths regardless of whether an exception occurs.
- Replace set_thirdparty_ext_root_dirs() with core.set_option() to avoid
  the existence-check rejection of temporarily-offline network shares when
  writing back the updated directory list.
- Capture the read exception and log it at debug level before falling back
  to the helper, replacing the silent bare 'except Exception' swallow.
@devloai
Copy link
Copy Markdown
Contributor

devloai bot commented Apr 3, 2026

Fix Summary

Applied two fixes to extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/Extensions.smartbutton/script.py in commit 418b18d:

Fix 1 — Offline-path preservation negated by write path (#3034420588)

The CONSTS import was moved outside the try block (so it's always available for both the read and write paths), and the write now uses user_config.core.set_option(CONSTS.ConfigsUserExtensionsKey, ...) directly instead of user_config.set_thirdparty_ext_root_dirs(). This avoids the existence check in the latter that would raise PyRevitException for any offline/non-existent path, defeating the whole purpose of reading the raw configured list. The write is also wrapped in its own try/except with logger.error (as the remote branch had already added).

Fix 2 — Silent exception swallowing hides config read failures (#3034420590)

The bare except Exception: block was changed to except Exception as read_err: and a logger.debug(...) call was added before falling back to the helper, making config read failures diagnosable without silently swallowing them.

@tay0thman
Copy link
Copy Markdown
Contributor Author

@devloai Assume that I did the fixes, review the whole script and report back

Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

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

Full Script Review — Extensions.smartbutton/script.py

The five Copilot-regression fixes are correct and well-targeted:

Fix Assessment
_ensure_path_registered: raw read via core.get_option ✅ Correct — avoids the op.exists() filter
_ensure_path_registered: raw write via core.set_option ✅ Correct — bypasses set_thirdparty_ext_root_dirs's existence check that would defeat offline-path preservation
Exception changed from bare except AttributeErrorexcept Exception as read_err + logger.debug ✅ Correct improvement to observability
Write wrapped in its own try/except with logger.error ✅ Correct — installation should not silently fail
[0]_get_default_ext_dir() in 4 call sites ✅ Correct — eliminates the IndexError on empty list

Two minor issues flagged:

  1. from pyrevit.userconfig import CONSTS inside function body (line 60) — CONSTS is a module-level symbol in userconfig.py; move it to the top-level import at line 15.
  2. Missing os.path.expandvars() on raw read (line 63) — get_thirdparty_ext_root_dirs applies expandvars before comparing; the raw read does not, so env-variable-style paths like %APPDATA%\extensions won't match on comparison and will be double-registered.

Overall the core logic is sound and the stated regressions are resolved. 🎉

Suggestions

  • Move CONSTS import to module level (line 15) Apply
  • Apply os.path.expandvars() when reading raw dirs (line 63) Apply

Apply all quick fixes (2 quick fixes)

@devloai
Copy link
Copy Markdown
Contributor

devloai bot commented Apr 3, 2026

Fix Summary

Applied two fixes to extensions/pyRevitCore.extension/pyRevit.tab/pyRevit.panel/Extensions.smartbutton/script.py:

Fix 1 — Move CONSTS to module-level import (comment #3034445665)

  • Added CONSTS to the existing module-level import: from pyrevit.userconfig import user_config, CONSTS
  • Removed the redundant from pyrevit.userconfig import CONSTS that was inside the _ensure_path_registered function body (previously executed on every call)

Fix 2 — Expand environment variables in raw_dirs before normalization (comment #3034445672)

  • Changed raw_dirs = list(user_config.core.get_option(...)) to use a list comprehension that calls os.path.expandvars(d) on each entry, ensuring paths like %APPDATA%\pyRevit-extra are fully resolved before normalization. This prevents double-registration when the stored paths contain environment variable references.

@tay0thman
Copy link
Copy Markdown
Contributor Author

Edits Tested locally and works fine. @jmcouffin

@jmcouffin jmcouffin closed this Apr 4, 2026
@jmcouffin jmcouffin reopened this Apr 4, 2026
@jmcouffin jmcouffin merged commit ad80bff into develop Apr 4, 2026
2 checks passed
@jmcouffin jmcouffin deleted the tay0thman-Fix-Regressions-cause-by-Copilot-Auto-Fix branch April 4, 2026 07:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

📦 New work-in-progress (wip) builds are available for 6.3.0.26094+0727-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

📦 New work-in-progress (wip) builds are available for 6.3.0.26095+0645-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

📦 New public release are available for 6.3.0.26095+0830

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.

2 participants