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

'NoneType' object has no attribute 'tree_id' #428

Closed
robslotboom opened this issue Jan 4, 2016 · 4 comments
Closed

'NoneType' object has no attribute 'tree_id' #428

robslotboom opened this issue Jan 4, 2016 · 4 comments

Comments

@robslotboom
Copy link

Updating a root elements fiels which is the "order_insertion_by" raises:

'NoneType' object has no attribute 'tree_id'

I solved this bij adding two lines of code.

def _make_sibling_of_root_node(self, node, target, position):
    ...
    elif position == 'right':
        if target_tree_id > tree_id:
            new_tree_id = target_tree_id
            lower_bound, upper_bound = tree_id, target_tree_id
            shift = -1
        else:
            right_sibling = target.get_next_sibling()
            if node == right_sibling:
                return
            # Addition
            if not right_sibling:
                return
            # end of addition
            new_tree_id = getattr(right_sibling, self.tree_id_attr)
            lower_bound, upper_bound = new_tree_id, tree_id
            shift = 1
@matthiask
Copy link
Member

Thank you for the report! Do you have some additional details such as the model itself? Will probably be a big help for constructing a test case.

@mullakhmetov
Copy link

I got the same error.
Environment: python 2.7.10, Django 1.9.1, django-mptt 0.8.4

# models.py
class Foo(MPTTModel):
    test = models.CharField(max_length=5)
    parent = TreeForeignKey('self', null=True, blank=True)

screen shot 2016-07-20 at 17 06 39

@matthiask
Copy link
Member

Nice, now I can reproduce this, even without order_insertion_by.

It seems that setting parent_id does not reset parent in any way, resp. parent isn't dynamically loaded from the database just because the underlying id field has some value.

(As you have seen assigning parent directly works fine.)

@matthiask
Copy link
Member

Additional testing reveals that this works:

f1 = Foo.objects.create()
f2 = Foo.objects.create()
f2.parent_id = f1.id
del f2._parent_cache  # Remove cached value of "None"
f2.save()

matthiask added a commit to matthiask/django-mptt that referenced this issue Jul 20, 2016
* master:
  Fix django-mptt#428: Do not crash when saving after direct assignment of parent_id
matthiask added a commit to matthiask/django-mptt that referenced this issue Jul 21, 2016
* upstream/0.8.x: (23 commits)
  0.8.5
  Fix the tests on 0.8.x branch. We don't have list filters in 0.8.x
  Fix django-mptt#428: Do not crash when saving after direct assignment of parent_id
  Fix django-mptt#480: Broken links in README
  Keep the state of nodes when opening new tabs
  Tutorial: Run makemigrations before migrate
  Replaced syncdb by migrate
  Multiple databases configuration support
  Refs django-mptt#455: Recommend running rebuild() inside a transaction
  Fix django-mptt#465: DraggableMPTTAdmin: Ignore arrow keys for navigation when on form element
  Fix django-mptt#475: Remove Django from install_requires
  Fix django-mptt#473: _meta has no attribute concrete_managers
  fix more using get_db_prep_value
  Fix TreeManager._move_child_within_tree breaks with UUIDField() as primary key.
  Provide for the new 'required' input attribute in Django 1.10
  Exclude tests from installed packages
  Stop using Model._deferred private attribute
  Simplified runtests.sh
  Add exclude djmaster & (py32,py33) exclude in TravisCI
  Add django master to failurable tests in TravisCI
  ...
matthiask added a commit to matthiask/django-mptt that referenced this issue Jul 21, 2016
* master: (25 commits)
  0.8.5
  Fix the tests on 0.8.x branch. We don't have list filters in 0.8.x
  0.8.5
  Fix django-mptt#428: Do not crash when saving after direct assignment of parent_id
  Fix django-mptt#428: Do not crash when saving after direct assignment of parent_id
  Fix django-mptt#480: Broken links in README
  Keep the state of nodes when opening new tabs
  Tutorial: Run makemigrations before migrate
  Replaced syncdb by migrate
  Multiple databases configuration support
  Refs django-mptt#455: Recommend running rebuild() inside a transaction
  Fix django-mptt#465: DraggableMPTTAdmin: Ignore arrow keys for navigation when on form element
  Fix django-mptt#475: Remove Django from install_requires
  Fix django-mptt#473: _meta has no attribute concrete_managers
  fix more using get_db_prep_value
  Fix TreeManager._move_child_within_tree breaks with UUIDField() as primary key.
  Provide for the new 'required' input attribute in Django 1.10
  Exclude tests from installed packages
  Stop using Model._deferred private attribute
  Simplified runtests.sh
  ...
barsgithub pushed a commit to barsgroup/m3-core that referenced this issue Aug 1, 2016
Присвоение связей mptt через _id вызывает неверное поведение.
django-mptt/django-mptt#428
barsgithub pushed a commit to barsgroup/m3-core that referenced this issue Aug 1, 2016
Присвоение связей mptt через _id вызывает неверное поведение.
django-mptt/django-mptt#428
barsgithub pushed a commit to barsgroup/m3-core that referenced this issue Aug 1, 2016
Присвоение связей mptt через _id вызывает неверное поведение.
django-mptt/django-mptt#428
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

3 participants