Comments (3)
Seems the doc has no stopped_at
field, but mongoengine.Document
can has the field that doesn't exist in the doc as None
.
Wired. Do you mind if I ask you to provide the doc schema?
from mongoengine-goodjson.
This reproduced the error for me:
from mongoengine import *
import mongoengine_goodjson as gj
from datetime import datetime
connect(host='mongodb://<ip>:27017/test')
STATES = ('PENDING','SOMETHING')
class Scanner(gj.Document):
session_name = StringField(required=True, unique=True)
cid = StringField()
zzz = StringField()
xxx = StringField()
yyy = StringField()
state = StringField(choices=STATES, default=u'PENDING')
created_at = DateTimeField(default=datetime.now)
online_at = DateTimeField()
started_at = DateTimeField()
stopped_at = DateTimeField()
scan_start = DateTimeField()
scan_complete = DateTimeField()
destroyed_at = DateTimeField()
s1 = Scanner(session_name='s1', online_at=datetime.now())
s1.save()
s2 = Scanner(session_name='s2', started_at=datetime.now())
s2.save()
Then
>>> Scanner.objects[0].to_json()
'{"created_at": "2017-04-03T09:45:55.926000", "session_name": "s1", "online_at": "2017-04-03T09:45:55.926000", "state": "PENDING", "id": "58e27c4407d32b9fd13f98b0"}'
>>> Scanner.objects[1].to_json()
'{"created_at": "2017-04-03T09:46:00.526000", "session_name": "s2", "started_at": "2017-04-03T09:46:00.526000", "state": "PENDING", "id": "58e27c4807d32b9fd13f98b1"}'
>>> Scanner.objects[0:1].to_json()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/<user>/.pyenv/versions/automation/lib/python2.7/site-packages/mongoengine_goodjson/queryset.py", line 80, in to_json
lst = self.as_pymongo()
File "/Users/<user>/.pyenv/versions/automation/lib/python2.7/site-packages/mongoengine_goodjson/queryset.py", line 70, in as_pymongo
item[name] = self.__get_doc(fld, item[name])
KeyError: 'zzz'
from mongoengine-goodjson.
Using array slice style, somehow mongoengine.QuerySet
returns a list, but using skip
and limit
, I can see this bug.
from mongoengine-goodjson.
Related Issues (20)
- Possibility to add model class properties in to_json()? HOT 2
- Serialization of DictField of ReferenceField HOT 11
- 2.0? HOT 1
- `DynamicField` to_json error HOT 2
- convert pipeline query result to JSON? HOT 4
- Pushing an Id to db.ListField(gj.FollowReferenceField()) adds an entire object HOT 3
- got an unexpected keyword argument 'follow_reference' HOT 1
- __unset_gj_flag_sub_field has sometimes raises error. HOT 1
- Deprecation Warning When Executing Alongside Pytest HOT 7
- Unexpected Error while saving Document in MongoEngine after using mongoengine-goodjson HOT 1
- Custom QuerySet cancels goodjson
- Dependency Dashboard
- compatibility problems HOT 2
- No ID replace when returning list of objects HOT 4
- BooleanField to python for "False" executes to True in generate_object_hook HOT 6
- Is there a way to specify which format a DatetimeField will be resolved to? HOT 3
- Documentation
- Make ID attribute the first property HOT 1
- Problem with empty list HOT 4
- Poetry HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoengine-goodjson.