Skip to content

Avoid "<type> None" in CustomObject.__str__ post-delete#528

Closed
Kani999 wants to merge 1 commit into
netboxlabs:mainfrom
Kani999:feature/customobject-str-fallback
Closed

Avoid "<type> None" in CustomObject.__str__ post-delete#528
Kani999 wants to merge 1 commit into
netboxlabs:mainfrom
Kani999:feature/customobject-str-fallback

Conversation

@Kani999
Copy link
Copy Markdown

@Kani999 Kani999 commented May 26, 2026

Summary

CustomObject.__str__ includes self.id in its fallback output when no field on the COT is marked primary=True. But Django's Model.delete() sets self.pk to None after the database row is removed — and NetBox's delete-toast and changelog renderers call str() on the post-delete instance. The result is a literal "None" in the user-facing message:

Deleted SmokeTabTarget SmokeTabTarget None

Fix

Branch on self.pk inside the no-primary-field path:

  • self.pk is None (post-delete) → return just the COT's display name ("SmokeTabTarget").
  • self.pk is set (normal rendering) → behave as before ("SmokeTabTarget 5").

8 lines, no behavioural change for any code path with a live pk.

Verification

Observed while smoke-testing PR #482's related-tabs work.

Context

Surfaced during the related-object-tabs smoke testing (PR #482); independent of that work and easy enough to land standalone.

Django's Model.delete() sets self.pk to None after the DB row is gone.
NetBox's delete-toast and changelog renderers call str() on the
post-delete instance, so when the COT has no primary=True field the
previous output included a literal "None":

  Deleted SmokeTabTarget SmokeTabTarget None

Branch on self.pk: when None, return just the COT's display name
("SmokeTabTarget"); when set, behave as before ("SmokeTabTarget 5").

Observed during the all-in-one smoke run on krupa.vm.cesnet.cz on
2026-05-26 while validating PR netboxlabs#482's related-tabs work.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Kani999 Kani999 mentioned this pull request May 26, 2026
@bctiemann
Copy link
Copy Markdown
Contributor

bctiemann commented May 26, 2026

Hi @Kani999 , as with the other PR just now, please don't open a PR unless there is an accepted bug to link it to (this is for later bookkeeping/forensics). Please open a bug issue with repro steps and any relevant details according to the template, and then once it's triaged and accepted we can reopen this PR. Thanks!

@bctiemann bctiemann closed this May 26, 2026
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