Skip to content

Comments

Fixes #428: Handle None values in ChangeDiff diff properties#433

Open
jnovinger wants to merge 2 commits intomainfrom
fix/428-changediff-none-diff-properties
Open

Fixes #428: Handle None values in ChangeDiff diff properties#433
jnovinger wants to merge 2 commits intomainfrom
fix/428-changediff-none-diff-properties

Conversation

@jnovinger
Copy link
Contributor

Fixes: #428

Fixes AttributeError when viewing the Diff tab for objects created or deleted in a branch.

Adds None guards to ChangeDiff properties that call .items() on potentially None fields:

  • original_diff - returns {} when original is None (CREATE actions)
  • modified_diff - returns {} when modified is None (DELETE actions)
  • current_diff - returns {} when current is None (branch-created objects)
  • altered_in_modified - returns set() when modified or original is None
  • altered_in_current - returns set() when current or original is None

Scenarios fixed:

  • CREATE: original=None, modified={...}, current=None
  • DELETE: original={...}, modified=None, current={...}
  • UPDATE on branch-created object: original={...}, modified={...}, current=None

When viewing the Diff tab for objects created in a branch, the page
crashed because original_diff called .items() on None. For CREATE
actions, original is None since the object didn't exist before.

Adds None guards to:
- original_diff: return {} if original is None
- current_diff: return {} if current is None
- altered_in_modified: return set() if modified or original is None
- altered_in_current: return set() if current or original is None
@jnovinger jnovinger marked this pull request as ready for review February 17, 2026 18:46
@jnovinger jnovinger requested review from a team and jeremystretch and removed request for a team February 17, 2026 18:46
Extends the None handling to cover DELETE actions where modified is
None since deleted objects have no postchange_data.

Also adds test coverage for UPDATE actions on branch-created objects
where current is None (already covered by the previous commit's guards).
@jnovinger jnovinger force-pushed the fix/428-changediff-none-diff-properties branch from 7099b9d to c2d6dac Compare February 17, 2026 18:55
@jeremystretch
Copy link
Contributor

@jnovinger could you expand on the reproduction steps in #428? I'm not sure how to reproduce the bug before verifying the fix. Does this involve netbox-changes as well?

  1. Create a branch and activate it
  2. Create or update any object with custom fields (e.g., circuit termination, device)
  3. View the Changes tab in the change request
  4. Or attempt to revert the branch

@jeremystretch jeremystretch removed their request for review February 20, 2026 14:07
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.

AttributeError in ChangeDiff._update_conflicts when self.modified is None

2 participants