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

AttributeError: 'NoneType' object has no attribute 'split' #1

Closed
bartTC opened this issue Apr 25, 2009 · 1 comment
Closed

AttributeError: 'NoneType' object has no attribute 'split' #1

bartTC opened this issue Apr 25, 2009 · 1 comment

Comments

@bartTC
Copy link

bartTC commented Apr 25, 2009

I'm not sure when or why this happens, but sometimes after saving a comment (not a reply to another comment) the annotate_tree filter isn't working, but the comment itself was saved successfully:

File "threadedcomments/models.py", line 16, in _get_depth
if self.tree_path.split is not None:
AttributeError: 'NoneType' object has no attribute 'split'

A quick workaround saves me from this:

diff --git a/threadedcomments/models.py b/threadedcomments/models.py
index 61c8587..7c45e0f 100644
--- a/threadedcomments/models.py
+++ b/threadedcomments/models.py
@@ -13,11 +13,14 @@ class ThreadedComment(Comment):
     tree_path = models.TextField(null=True, blank=True, db_index=True)

     def _get_depth(self):
-        return len(self.tree_path.split(PATH_SEPARATOR))
+        if self.tree_path is not None:
+            return len(self.tree_path.split(PATH_SEPARATOR))
+        return 1
     depth = property(_get_depth)

     def _root_id(self):
-        return self.tree_path.split(PATH_SEPARATOR)[0]
+        if self.tree_path is not None:
+            return self.tree_path.split(PATH_SEPARATOR)[0]
     root_id = property(_root_id)

     def save(self, *args, **kwargs):
@honzakral
Copy link
Owner

I changed the field not to be nullable so this error shouldn't happen again. Another matter entirely is, however, how it came to be that the tree_path wasn't constucted on the comment's save()

This issue was closed.
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

No branches or pull requests

2 participants