From 825922a468d0b3ef1071cab35334376e6a41c93f Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 12 Jul 2018 10:45:35 -0400 Subject: [PATCH 01/17] Hack that fixes unit test --- mongoengine/base/datastructures.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index fddd945a2..f3f23bd9c 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -88,11 +88,16 @@ def update(self, *args, **kwargs): return super(BaseDict, self).update(*args, **kwargs) def _mark_as_changed(self, key=None): - if hasattr(self._instance, '_mark_as_changed'): - if key: - self._instance._mark_as_changed('%s.%s' % (self._name, key)) - else: - self._instance._mark_as_changed(self._name) + try: + if hasattr(self._instance, '_mark_as_changed'): + if key: + self._instance._mark_as_changed( + '%s.%s' % (self._name, key % len(self)) + ) + else: + self._instance._mark_as_changed(self._name) + except ReferenceError: + pass class BaseList(list): From 404d8c19e29372770e42d99bd8b7d3d84d64fa18 Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 12 Jul 2018 12:57:48 -0400 Subject: [PATCH 02/17] Added TypeError to exception list --- mongoengine/base/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index f3f23bd9c..9e72b107a 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -96,7 +96,7 @@ def _mark_as_changed(self, key=None): ) else: self._instance._mark_as_changed(self._name) - except ReferenceError: + except (ReferenceError, TypeError): pass From 7f0d184259db2431dc58af3ba1b2249ed62f510c Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 12 Jul 2018 14:05:38 -0400 Subject: [PATCH 03/17] Revert changes --- mongoengine/base/datastructures.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 9e72b107a..b16ac40ba 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -88,6 +88,14 @@ def update(self, *args, **kwargs): return super(BaseDict, self).update(*args, **kwargs) def _mark_as_changed(self, key=None): + if hasattr(self._instance, '_mark_as_changed'): + if key: + self._instance._mark_as_changed( + '%s.%s' % (self._name, key % len(self)) + ) + else: + self._instance._mark_as_changed(self._name) + """ try: if hasattr(self._instance, '_mark_as_changed'): if key: @@ -98,7 +106,7 @@ def _mark_as_changed(self, key=None): self._instance._mark_as_changed(self._name) except (ReferenceError, TypeError): pass - + """ class BaseList(list): """A special list so we can watch any changes.""" From 61aeeabce90f04d56328147d5128e006f7eb671c Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 12 Jul 2018 14:09:20 -0400 Subject: [PATCH 04/17] try again --- mongoengine/base/datastructures.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index b16ac40ba..1298dc44a 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -88,25 +88,21 @@ def update(self, *args, **kwargs): return super(BaseDict, self).update(*args, **kwargs) def _mark_as_changed(self, key=None): + """ if hasattr(self._instance, '_mark_as_changed'): if key: - self._instance._mark_as_changed( - '%s.%s' % (self._name, key % len(self)) - ) + self._instance._mark_as_changed('%s.%s' % (self._name, key)) else: self._instance._mark_as_changed(self._name) """ try: if hasattr(self._instance, '_mark_as_changed'): if key: - self._instance._mark_as_changed( - '%s.%s' % (self._name, key % len(self)) - ) + self._instance._mark_as_changed('%s.%s' % (self._name, key)) else: self._instance._mark_as_changed(self._name) except (ReferenceError, TypeError): pass - """ class BaseList(list): """A special list so we can watch any changes.""" From 1811bf544d0984656467794414559dae2167117e Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 08:35:04 -0400 Subject: [PATCH 05/17] Debug prints in __init__ for BaseList --- mongoengine/base/datastructures.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 1298dc44a..6e276a7a9 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -112,12 +112,14 @@ class BaseList(list): _name = None def __init__(self, list_items, instance, name): + print("BaseList.__init__") Document = _import_class('Document') EmbeddedDocument = _import_class('EmbeddedDocument') if isinstance(instance, (Document, EmbeddedDocument)): self._instance = weakref.proxy(instance) self._name = name + print("BaseList.__init__ _instance(%s)" % this._instance) super(BaseList, self).__init__(list_items) def __getitem__(self, key, *args, **kwargs): @@ -216,7 +218,6 @@ def _mark_as_changed(self, key=None): class EmbeddedDocumentList(BaseList): - @classmethod def __match_all(cls, embedded_doc, kwargs): """Return True if a given embedded doc matches all the filter kwargs. If it doesn't return False. From 870f15ffb5e43386dadecc9ef549bc90ce7f107b Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 08:39:14 -0400 Subject: [PATCH 06/17] this -> self --- mongoengine/base/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 6e276a7a9..f9b1994eb 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -119,7 +119,7 @@ def __init__(self, list_items, instance, name): if isinstance(instance, (Document, EmbeddedDocument)): self._instance = weakref.proxy(instance) self._name = name - print("BaseList.__init__ _instance(%s)" % this._instance) + print("BaseList.__init__ _instance(%s)" % self._instance) super(BaseList, self).__init__(list_items) def __getitem__(self, key, *args, **kwargs): From dc0d256e46f2010c0a332b99ec45ce3317914a02 Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 08:40:31 -0400 Subject: [PATCH 07/17] more print --- mongoengine/base/datastructures.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index f9b1994eb..829d73975 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -113,6 +113,9 @@ class BaseList(list): def __init__(self, list_items, instance, name): print("BaseList.__init__") + print("list_items: %s" % list_items) + print("instance: %s" % instance) + print("name: %s" % name) Document = _import_class('Document') EmbeddedDocument = _import_class('EmbeddedDocument') From 4fa3da662c15c382a621a312c61fb5da3db3ff67 Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 08:43:09 -0400 Subject: [PATCH 08/17] . --- mongoengine/base/datastructures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 829d73975..59b18d18b 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -123,6 +123,7 @@ def __init__(self, list_items, instance, name): self._instance = weakref.proxy(instance) self._name = name print("BaseList.__init__ _instance(%s)" % self._instance) + print("----------------------------\n" super(BaseList, self).__init__(list_items) def __getitem__(self, key, *args, **kwargs): From b393639a1c031877554eaecd5e3dd2d5b63e40cc Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 08:44:03 -0400 Subject: [PATCH 09/17] . --- mongoengine/base/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 59b18d18b..8f00b789f 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -123,7 +123,7 @@ def __init__(self, list_items, instance, name): self._instance = weakref.proxy(instance) self._name = name print("BaseList.__init__ _instance(%s)" % self._instance) - print("----------------------------\n" + print("----------------------------\n") super(BaseList, self).__init__(list_items) def __getitem__(self, key, *args, **kwargs): From 1955006d7b541c8f50998ea4a39690f16583c22a Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 10:29:17 -0400 Subject: [PATCH 10/17] Removed prints --- mongoengine/base/datastructures.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 8f00b789f..d6ed67694 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -112,18 +112,12 @@ class BaseList(list): _name = None def __init__(self, list_items, instance, name): - print("BaseList.__init__") - print("list_items: %s" % list_items) - print("instance: %s" % instance) - print("name: %s" % name) Document = _import_class('Document') EmbeddedDocument = _import_class('EmbeddedDocument') if isinstance(instance, (Document, EmbeddedDocument)): self._instance = weakref.proxy(instance) self._name = name - print("BaseList.__init__ _instance(%s)" % self._instance) - print("----------------------------\n") super(BaseList, self).__init__(list_items) def __getitem__(self, key, *args, **kwargs): From 05e0f5b347989a62590a404f6deeb5d49fc43c64 Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 10:40:56 -0400 Subject: [PATCH 11/17] Comment out try/except block --- mongoengine/base/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index d6ed67694..cc42a71d2 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -88,7 +88,6 @@ def update(self, *args, **kwargs): return super(BaseDict, self).update(*args, **kwargs) def _mark_as_changed(self, key=None): - """ if hasattr(self._instance, '_mark_as_changed'): if key: self._instance._mark_as_changed('%s.%s' % (self._name, key)) @@ -103,6 +102,7 @@ def _mark_as_changed(self, key=None): self._instance._mark_as_changed(self._name) except (ReferenceError, TypeError): pass + """ class BaseList(list): """A special list so we can watch any changes.""" From 979788599f8a497219d6696789834e19500bd738 Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 10:54:01 -0400 Subject: [PATCH 12/17] Add classmethod back in --- mongoengine/base/datastructures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index cc42a71d2..ce867258d 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -216,6 +216,7 @@ def _mark_as_changed(self, key=None): class EmbeddedDocumentList(BaseList): + #classmethod def __match_all(cls, embedded_doc, kwargs): """Return True if a given embedded doc matches all the filter kwargs. If it doesn't return False. From cfdc42edb9df246b8de517b1fd14c2b2598b3649 Mon Sep 17 00:00:00 2001 From: Furr Date: Fri, 13 Jul 2018 10:54:40 -0400 Subject: [PATCH 13/17] . --- mongoengine/base/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index ce867258d..f058d7dc1 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -216,7 +216,7 @@ def _mark_as_changed(self, key=None): class EmbeddedDocumentList(BaseList): - #classmethod + @classmethod def __match_all(cls, embedded_doc, kwargs): """Return True if a given embedded doc matches all the filter kwargs. If it doesn't return False. From 57af37209c8c0c93b91c25d6ce3b5ce5f24e20e5 Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 16 Aug 2018 13:20:30 -0400 Subject: [PATCH 14/17] Stop usign weakref in BaseDict --- mongoengine/base/datastructures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index f058d7dc1..4b90fd72d 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -22,7 +22,7 @@ def __init__(self, dict_items, instance, name): EmbeddedDocument = _import_class('EmbeddedDocument') if isinstance(instance, (Document, EmbeddedDocument)): - self._instance = weakref.proxy(instance) + self._instance = instance self._name = name super(BaseDict, self).__init__(dict_items) From b5d9bce633d023aeb7b3e205cd3144c861c54f5f Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 16 Aug 2018 13:21:30 -0400 Subject: [PATCH 15/17] Remove commented out code --- mongoengine/base/datastructures.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index 4b90fd72d..cc0ee93b1 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -93,16 +93,6 @@ def _mark_as_changed(self, key=None): self._instance._mark_as_changed('%s.%s' % (self._name, key)) else: self._instance._mark_as_changed(self._name) - """ - try: - if hasattr(self._instance, '_mark_as_changed'): - if key: - self._instance._mark_as_changed('%s.%s' % (self._name, key)) - else: - self._instance._mark_as_changed(self._name) - except (ReferenceError, TypeError): - pass - """ class BaseList(list): """A special list so we can watch any changes.""" From d54c75f95208cc56675a7e71cbda56c628741c1e Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 16 Aug 2018 13:21:59 -0400 Subject: [PATCH 16/17] readd space for lint --- mongoengine/base/datastructures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index cc0ee93b1..ab9133a4d 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -94,6 +94,7 @@ def _mark_as_changed(self, key=None): else: self._instance._mark_as_changed(self._name) + class BaseList(list): """A special list so we can watch any changes.""" From e92176ff5a6063cfa9c99e622a7ad406fb9cc940 Mon Sep 17 00:00:00 2001 From: Furr Date: Thu, 16 Aug 2018 13:24:39 -0400 Subject: [PATCH 17/17] remove weakref alltogether --- mongoengine/base/datastructures.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mongoengine/base/datastructures.py b/mongoengine/base/datastructures.py index ab9133a4d..3ba01252a 100644 --- a/mongoengine/base/datastructures.py +++ b/mongoengine/base/datastructures.py @@ -1,5 +1,4 @@ import itertools -import weakref from bson import DBRef import six @@ -107,7 +106,7 @@ def __init__(self, list_items, instance, name): EmbeddedDocument = _import_class('EmbeddedDocument') if isinstance(instance, (Document, EmbeddedDocument)): - self._instance = weakref.proxy(instance) + self._instance = instance self._name = name super(BaseList, self).__init__(list_items)