Skip to content

Fixes #3898: Call str of cable on delete to save PK in id_string #3899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 13, 2020
Merged

Fixes #3898: Call str of cable on delete to save PK in id_string #3899

merged 5 commits into from
Jan 13, 2020

Conversation

hSaria
Copy link
Contributor

@hSaria hSaria commented Jan 12, 2020

Fixes: #3898

Called the __str__ method of the cable to create the self.id_string attribute if not there. An alternative solution would've been to move the msg line before delete() is called, but I checked all models' __str__ method and it's only Cable that uses the PK as part of the string.

try:
obj.delete()
except ProtectedError as e:
handle_protectederror(obj, request, e)
return redirect(obj.get_absolute_url())
msg = 'Deleted {} {}'.format(self.model._meta.verbose_name, obj)

@jeremystretch
Copy link
Member

My fix for this under #2984 was admittedly naive, since it requires calling str() on the cable instance first. We can do this more efficiently by setting self._pk = self.pk on init, and having __str__ return self.label or self._pk.

@hSaria
Copy link
Contributor Author

hSaria commented Jan 13, 2020

Yep, that'd be cleaner. Let me adjust the PR.

@hSaria hSaria requested a review from jeremystretch January 13, 2020 15:28
@jeremystretch jeremystretch merged commit cf48037 into netbox-community:develop Jan 13, 2020
@hSaria hSaria deleted the 3898-cable-str-pk branch January 13, 2020 16:41
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Message when disconnecting a cable not showing ID
2 participants