Git Product home page Git Product logo

Comments (3)

hiroaki-yamamoto avatar hiroaki-yamamoto commented on June 5, 2024

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.

vetsin avatar vetsin commented on June 5, 2024

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.

hiroaki-yamamoto avatar hiroaki-yamamoto commented on June 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.