Fixes #428: Handle None values in ChangeDiff diff properties#433
Open
Fixes #428: Handle None values in ChangeDiff diff properties#433
Conversation
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
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).
7099b9d to
c2d6dac
Compare
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?
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #428
Fixes
AttributeErrorwhen 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{}whenoriginalis None (CREATE actions)modified_diff- returns{}whenmodifiedis None (DELETE actions)current_diff- returns{}whencurrentis None (branch-created objects)altered_in_modified- returnsset()whenmodifiedororiginalis Nonealtered_in_current- returnsset()whencurrentororiginalis NoneScenarios fixed:
original=None,modified={...},current=Noneoriginal={...},modified=None,current={...}original={...},modified={...},current=None