From 349d6198047789fbe961a935ef868faf0a137fd8 Mon Sep 17 00:00:00 2001 From: Shaoyu Date: Thu, 4 Apr 2019 14:45:39 -0500 Subject: [PATCH 1/2] make sure dbref encoded correctly --- eve/io/mongo/mongo.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/eve/io/mongo/mongo.py b/eve/io/mongo/mongo.py index b711e9b95..7d489fb84 100644 --- a/eve/io/mongo/mongo.py +++ b/eve/io/mongo/mongo.py @@ -24,6 +24,7 @@ from werkzeug.exceptions import HTTPException import decimal from bson import decimal128 +from collections import OrderedDict from eve.auth import resource_auth from eve.io.base import DataLayer, ConnectionException, BaseJSONEncoder @@ -41,6 +42,9 @@ class MongoJSONEncoder(BaseJSONEncoder): """ Proprietary JSONEconder subclass used by the json render function. This is needed to address the encoding of special values. + .. versionchanged:: 0.8.2 + Key-value pair order in DBRef are honored when encoding. Closes #1255. + .. versionchanged:: 0.6.2 Do not attempt to serialize callables. Closes #790. @@ -57,7 +61,9 @@ def default(self, obj): # (and we probably don't want it to be exposed anyway). See #790. return "" if isinstance(obj, DBRef): - retval = {"$id": str(obj.id), "$ref": obj.collection} + retval = OrderedDict() + retval["$ref"] = obj.collection + retval["$id"] = str(obj.id) if obj.database: retval["$db"] = obj.database return retval From 68b8d38d61380ac9a413309095999b70219fbce1 Mon Sep 17 00:00:00 2001 From: Nicola Iarocci Date: Fri, 5 Apr 2019 09:13:08 +0200 Subject: [PATCH 2/2] Changelog for #1256 --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index f009a8607..7d68523b3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -21,6 +21,7 @@ New Fixed ~~~~~ +- Insertion failure when replacing unknown field with dbref value (`#1255`_) - ``max_results=1`` should be honored on aggregation endpoints (`#1250`_) - PATCH incorrectly normalizes default values in subdocuments (`#1234`_) - Unauthorized Exception not working with Werkzeug >= 15.0 (`#1245`_, `#1251`_) @@ -62,6 +63,7 @@ Improved - Add a "Python 3 is highly preferred" note on the homepage (`#1198`_) - Drop sphinx-contrib-embedly when building docs. +.. _`#1255`: https://github.com/pyeve/eve/issues/1255 .. _`#1250`: https://github.com/pyeve/eve/issues/1250 .. _`#1234`: https://github.com/pyeve/eve/issues/1234 .. _`#1251`: https://github.com/pyeve/eve/pull/1251