Skip to content
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

Fix for deleting a comment with a parent but no siblings (for issue #50) #51

Closed
wants to merge 1 commit into from

Conversation

rodrigogadea
Copy link

No description provided.

.order_by('-submit_date')\
.values_list('pk', flat=True)
parent = ThreadedComment.objects.filter(pk=self.parent_id)
if len(siblings) > 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually quite unnecessary - it would be easier to just leave the [0] access and catch any exceptions and use None instead.

Also if you could please attach tests.

Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't write the tests now, but I think one should wrap on try if there is something like .get(), that rises an exception if it can't find anything.

If you are using filter(), it will always return something, so one should discuss about the returned value (that's the if len()).

The amount of queries are the same, when you call [0], the queryset gets evaluated, so it is when you call values_list(). Then the parent query gets executed when update() is called (I think).

It's a matter of preferences, whatever works best for you

@honzakral honzakral closed this Nov 18, 2013
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.

None yet

2 participants