Skip to content

SG-45127 Fix AttributeError in ShotgunHierarchyModel when first path is not loaded - #180

Open
stevelittlefish wants to merge 2 commits into
masterfrom
ticket/SG-45127-hierarchy-model-nonetype
Open

SG-45127 Fix AttributeError in ShotgunHierarchyModel when first path is not loaded#180
stevelittlefish wants to merge 2 commits into
masterfrom
ticket/SG-45127-hierarchy-model-nonetype

Conversation

@stevelittlefish

Copy link
Copy Markdown
Contributor

Problem

ShotgunHierarchyModel.async_item_from_paths raised AttributeError: 'NoneType' object has no attribute 'index' whenever the first path in the list was not yet loaded in the model. This happens, for example, when an app such as the Loader auto-navigates to an entity while the model's root children have not been fetched yet. Reference: SG-45127.

Root cause

Two related defects in shotgun_hierarchy_model.py:

  1. async_item_from_paths sliced paths[idx - 1:] to hand _NodeRefresher an already-loaded ancestor at index 0 plus the awaited node at index 1. For idx == 0 this wrapped to paths[-1:] — the deepest, never-loaded path. The loop implicitly assumed the first path is always already loaded.

  2. _NodeRefresher.__init__ then called model.item_from_path(path_to_refresh[0]).index() unconditionally. Fed the deepest path by defect 1, item_from_path() returned None and .index() raised.

Fix

When idx == 0, refresh from the model root (self._path) — the first path's real parent, which always exists — instead of wrapping to the deepest path.

Guard _NodeRefresher.__init__ against item_from_path() returning None, aborting the refresh gracefully rather than crashing.

Testing

Added test_async_item_from_paths_first_path_not_loaded, which drives the idx == 0 branch and asserts it no longer raises.

Verified against the real model code that the previous logic crashed with the reported AttributeError while the updated logic refreshes from the root instead (nothing-loaded state aborts gracefully via the guard; root-loaded state issues a fetchMore on the root).

…is not loaded

async_item_from_paths crashed with "AttributeError: 'NoneType' object has no
attribute 'index'" whenever the first path in the list was not yet loaded in the
model (e.g. the Loader auto-navigating home during __init__ before the root's
children are fetched).

Two related defects in shotgun_hierarchy_model.py:

- async_item_from_paths sliced paths[idx - 1:] to hand _NodeRefresher an already
  loaded ancestor plus the awaited node. For idx == 0 that wrapped to paths[-1:]
  (the deepest, never-loaded path). The first path's real parent is the model
  root (self._path), which always exists, so refresh from there when idx == 0.

- _NodeRefresher.__init__ dereferenced item_from_path(path_to_refresh[0]).index()
  unconditionally. Guard against item_from_path() returning None and abort the
  refresh gracefully instead of crashing.

Adds a regression test that drives the idx == 0 branch and asserts it no longer
raises.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.32%. Comparing base (35f3736) to head (150f9b0).

Files with missing lines Patch % Lines
python/shotgun_model/shotgun_hierarchy_model.py 72.72% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   61.63%   62.32%   +0.69%     
==========================================
  Files          50       50              
  Lines        3412     3419       +7     
==========================================
+ Hits         2103     2131      +28     
+ Misses       1309     1288      -21     
Flag Coverage Δ
Linux 62.24% <72.72%> (+0.72%) ⬆️
Python-3.10 62.34% <72.72%> (+0.72%) ⬆️
Python-3.11 62.31% <72.72%> (+0.72%) ⬆️
Python-3.13 62.34% <72.72%> (+0.72%) ⬆️
Python-3.9 62.34% <72.72%> (+0.69%) ⬆️
Windows 62.26% <72.72%> (+0.69%) ⬆️
macOS 62.26% <72.72%> (+0.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stevelittlefish
stevelittlefish marked this pull request as ready for review September 4, 2026 15:11
@stevelittlefish
stevelittlefish requested a review from a team September 4, 2026 15:11

@carlos-villavicencio-adsk carlos-villavicencio-adsk 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.

LGTM

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