From 4bd72ebc636c84f2c92ffe0e8e8f7dfbe43e4b19 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Fri, 27 Feb 2015 11:32:06 +0200 Subject: [PATCH] Use None instead of mutable arguments. --- mongoengine/base/document.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mongoengine/base/document.py b/mongoengine/base/document.py index 6bf38ee2..5bc848f5 100644 --- a/mongoengine/base/document.py +++ b/mongoengine/base/document.py @@ -297,10 +297,13 @@ class BaseDocument(object): return self._data['_text_score'] - def to_mongo(self, use_db_field=True, fields=[]): + def to_mongo(self, use_db_field=True, fields=None): """ Return as SON data ready for use with MongoDB. """ + if not fields: + fields = [] + data = SON() data["_id"] = None data['_cls'] = self._class_name @@ -652,9 +655,11 @@ class BaseDocument(object): return cls._meta.get('collection', None) @classmethod - def _from_son(cls, son, _auto_dereference=True, only_fields=[], created=False): + def _from_son(cls, son, _auto_dereference=True, only_fields=None, created=False): """Create an instance of a Document (subclass) from a PyMongo SON. """ + if not only_fields: + only_fields = [] # get the class name from the document, falling back to the given # class if unavailable