From 19d5ed233807356a0eb774b0c74784804934da58 Mon Sep 17 00:00:00 2001 From: Diederik van der Boor Date: Mon, 8 Apr 2013 00:28:36 +0200 Subject: [PATCH] Fix base_manager unit test As more methods are added to the PolymorphicModel, the attr dict changes ordering in the meta class. By making the ordering of managers consistent, this problem no longer occurs. --- polymorphic/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/polymorphic/base.py b/polymorphic/base.py index c36b080..4004407 100644 --- a/polymorphic/base.py +++ b/polymorphic/base.py @@ -140,6 +140,11 @@ class PolymorphicModelBase(ModelBase): self.validate_model_manager(manager, self.__name__, key) add_managers.append((base.__name__, key, manager)) add_managers_keys.add(key) + + # The ordering in the base.__dict__ may randomly change depending on which method is added. + # Make sure base_objects is on top, and 'objects' and '_default_manager' follow afterwards. + # This makes sure that the _base_manager is also assigned properly. + add_managers = sorted(add_managers, key=lambda item: item[2].creation_counter, reverse=True) return add_managers @classmethod