Skip to content

Commit

Permalink
fix get_tree with emty table.
Browse files Browse the repository at this point in the history
  • Loading branch information
uralbash committed Jul 3, 2015
1 parent b0bc94d commit f754a90
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 46 deletions.
49 changes: 5 additions & 44 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.1.6 (2015-07-03)
==================

- fix bug with ``get_tree`` when no rows in database.

0.1.5 (2015-06-25)
==================

Expand Down Expand Up @@ -62,47 +67,3 @@ Bug Fixes

- Fix concurrency issue with multiple session (#36)
- Flushing the session now expire the instance and it's children (#33)

0.0.9 (2014-10-09)
==================

- Add MANIFEST.in
- New docs
- fixes in setup.py

0.0.8 (2014-08-15)
==================

- Add CONTRIBUTORS.txt

Features
--------

- Automatically register tree classes enhancement (#28)
- Added support polymorphic tree models (#24)

Bug Fixes
---------

- Fix expire left/right attributes of parent somewhen after the `before_insert` event (#30)
- Fix tree_id is incorrectly set to an existing tree if no parent is set (#23)
- Fix package is not installable if sqlalchemy is not (yet) installed (#22)

0.0.7 (2014-08-04)
==================

- Add LICENSE.txt

Bug Fixes
---------

- fix get_db_pk function


0.0.6 (2014-07-31)
==================

Bug Fixes
---------

- Allow the primary key to not be named "id" #20. See https://github.com/ITCase/sqlalchemy_mptt/issues/20
43 changes: 43 additions & 0 deletions CHANGES_OLD.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
0.0.9 (2014-10-09)
==================

- Add MANIFEST.in
- New docs
- fixes in setup.py

0.0.8 (2014-08-15)
==================

- Add CONTRIBUTORS.txt

Features
--------

- Automatically register tree classes enhancement (#28)
- Added support polymorphic tree models (#24)

Bug Fixes
---------

- Fix expire left/right attributes of parent somewhen after the `before_insert` event (#30)
- Fix tree_id is incorrectly set to an existing tree if no parent is set (#23)
- Fix package is not installable if sqlalchemy is not (yet) installed (#22)

0.0.7 (2014-08-04)
==================

- Add LICENSE.txt

Bug Fixes
---------

- fix get_db_pk function


0.0.6 (2014-07-31)
==================

Bug Fixes
---------

- Allow the primary key to not be named "id" #20. See https://github.com/ITCase/sqlalchemy_mptt/issues/20
2 changes: 1 addition & 1 deletion sqlalchemy_mptt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .mixins import BaseNestedSets
from .events import TreesManager

__version__ = "0.1.6.dev1"
__version__ = "0.1.6"
__mixins__ = [BaseNestedSets]
__all__ = ['BaseNestedSets', 'mptt_sessionmaker']

Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_mptt/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def query(nodes):
nodes = nodes.order_by(cls.tree_id, cls.level, cls.left).all()

# search minimal level of nodes.
min_level = min([node.level for node in nodes])
min_level = min([node.level for node in nodes] or [None])

def get_node_id(node):
return getattr(node, node.get_pk_name())
Expand Down
17 changes: 17 additions & 0 deletions sqlalchemy_mptt/tests/cases/get_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ def get_obj(session, model, id):

class Tree(object):

def test_get_empty_tree(self):
"""
No rows in database.
"""
self.session.query(self.model).delete()
self.session.flush()
tree = self.model.get_tree(self.session)
self.assertEqual(tree, [])

def test_get_empty_tree_with_custom_query(self):
"""
No rows with id < 0.
"""
query = lambda x: x.filter(self.model.get_pk_column() < 0)
tree = self.model.get_tree(self.session, query=query)
self.assertEqual(tree, [])

def test_get_tree(self):
""".. note::
Expand Down

0 comments on commit f754a90

Please sign in to comment.