Repository: MongoEngine/mongoengine

Issue:
Confusing error message when calling EmbeddedDocument.save
Trying to save an `EmbeddedDocumentField` says `NoneType` cannot be saved.
Shouldn't it be rather `EmbeddedDocumentField` cannot be saved ?


Discussion:
Hi @meain! Would you please share the schema you're using and the exact scenario in which you're getting that error?
@wojcikstefan  Sorry, it was actually for `EmbeddedDocument`

```python
class Platform(EmbeddedDocument):
    name = StringField(required=True)
    creds = DictField()
    enabled = BooleanField(default=False)
```

```python
In [1]: from mongoengine import StringField, DictField, BooleanField, EmbeddedDocument

In [2]: class Platform(EmbeddedDocument):
   ...:     '''Field for each platform'''
   ...:     name = StringField(required=True)
   ...:     creds = DictField()
   ...:     enabled = BooleanField(default=False)
   ...:

In [3]: pl = Platform(name='s', creds={}, enabled=True)

In [4]: pl.save()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-2b4ff9367580> in <module>()
----> 1 pl.save()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/document.pyc in save(self, *args, **kwargs)
     84
     85     def save(self, *args, **kwargs):
---> 86         self._instance.save(*args, **kwargs)
     87
     88     def reload(self, *args, **kwargs):

AttributeError: 'NoneType' object has no attribute 'save'

In [5]: type(pl)
Out[5]: __main__.Platform

In [6]: pl = Platform(name='s', creds={}, enabled=True).save()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-b8bb49457e96> in <module>()
----> 1 pl = Platform(name='s', creds={}, enabled=True).save()

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/document.pyc in save(self, *args, **kwargs)
     84
     85     def save(self, *args, **kwargs):
---> 86         self._instance.save(*args, **kwargs)
     87
     88     def reload(self, *args, **kwargs):

AttributeError: 'NoneType' object has no attribute 'save'

In [7]: type(Platform(name='s', creds={}, enabled=True))
Out[7]: __main__.Platform
```
embeddeddocument supposed to be not to call save method. Moreover, it should not have save method. both weird.
we should remove save() method from EmbeddedDocument class. I can submit PR

Resolving patch:
diff --git a/mongoengine/document.py b/mongoengine/document.py
--- a/mongoengine/document.py
+++ b/mongoengine/document.py
@@ -90,18 +90,6 @@ def to_mongo(self, *args, **kwargs):
 
         return data
 
-    def save(self, *args, **kwargs):
-        warnings.warn("EmbeddedDocument.save is deprecated and will be removed in a next version of mongoengine."
-                      "Use the parent document's .save() or ._instance.save()",
-                      DeprecationWarning, stacklevel=2)
-        self._instance.save(*args, **kwargs)
-
-    def reload(self, *args, **kwargs):
-        warnings.warn("EmbeddedDocument.reload is deprecated and will be removed in a next version of mongoengine."
-                      "Use the parent document's .reload() or ._instance.reload()",
-                      DeprecationWarning, stacklevel=2)
-        self._instance.reload(*args, **kwargs)
-
 
 class Document(six.with_metaclass(TopLevelDocumentMetaclass, BaseDocument)):
     """The base class used for defining the structure and properties of


Test patch:
diff --git a/tests/document/instance.py b/tests/document/instance.py
--- a/tests/document/instance.py
+++ b/tests/document/instance.py
@@ -3189,24 +3189,6 @@ def save(self, *args, **kwargs):
             "UNDEFINED",
             system.nodes["node"].parameters["param"].macros["test"].value)
 
-    def test_embedded_document_save_reload_warning(self):
-        """Relates to #1570"""
-        class Embedded(EmbeddedDocument):
-            pass
-
-        class Doc(Document):
-            emb = EmbeddedDocumentField(Embedded)
-
-        doc = Doc(emb=Embedded()).save()
-        doc.emb.save()  # Make sure its still working
-        with warnings.catch_warnings():
-            warnings.simplefilter("error", DeprecationWarning)
-            with self.assertRaises(DeprecationWarning):
-                doc.emb.save()
-
-            with self.assertRaises(DeprecationWarning):
-                doc.emb.reload()
-
     def test_embedded_document_equality(self):
         class Test(Document):
             field = StringField(required=True)