diff --git a/CHANGES.rst b/CHANGES.rst index fbb83ac..791f4b7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ================== @@ -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 diff --git a/CHANGES_OLD.rst b/CHANGES_OLD.rst new file mode 100644 index 0000000..ef2f1b4 --- /dev/null +++ b/CHANGES_OLD.rst @@ -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 diff --git a/sqlalchemy_mptt/__init__.py b/sqlalchemy_mptt/__init__.py index 303f98c..a96f42c 100644 --- a/sqlalchemy_mptt/__init__.py +++ b/sqlalchemy_mptt/__init__.py @@ -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'] diff --git a/sqlalchemy_mptt/mixins.py b/sqlalchemy_mptt/mixins.py index 8cf9c76..6a4eecf 100644 --- a/sqlalchemy_mptt/mixins.py +++ b/sqlalchemy_mptt/mixins.py @@ -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()) diff --git a/sqlalchemy_mptt/tests/cases/get_tree.py b/sqlalchemy_mptt/tests/cases/get_tree.py index 1cabd11..61ec239 100644 --- a/sqlalchemy_mptt/tests/cases/get_tree.py +++ b/sqlalchemy_mptt/tests/cases/get_tree.py @@ -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::