Giter VIP home page Giter VIP logo

eve-mongoengine's Introduction

Eve-MongoEngine

Info

Eve-MongoEngine provides MongoEngine integration with Eve.

Repository

https://github.com/hellerstanislav/eve-mongoengine

Author

Stanislav Heller (https://github.com/hellerstanislav)

Maintainer

Matthew Ellison (https://github.com/seglberg)


Production Development
travis-master travis-develop
Code Health Code Health

THE DEVELOP BRANCH CONTAINS POST-LEGACY WORK

See the legacy tag for the last legacy release (0.0.10).

Do not use develop in production code. Instead, the master branch always points to the latest production release, and should be used instead.

About

Eve-MongoEngine is an Eve extension, which enables MongoEngine ODM model to be used as an Eve / Cerberus schema. This eliminates the need to re-write API schemas in the Cerberus format by using MongoEngine models to automatically export a corresponding Cerberus schema.

Additional documentation and examples can be found on Read the Docs.

Installation

If you have pip installed you can use pip install eve-mongoengine. Otherwise, you can download the source from GitHub and run python setup.py install.

Dependencies

  • Python 2.7+ or Python 3.3+
  • eve>=0.5.3
  • mongoengine>=0.8.7,<=0.9
  • blinker

Optional Dependencies

  • None

Legacy Release

The legacy version of the extension can be found under the 'legacy' tag. The legacy version of the extension was released under the BSD-2 license and originally authored by Stanislav Heller. See AUTHORS for more information about the legacy authors and ownership.

eve-mongoengine's People

Contributors

dmitryax avatar hellerstanislav avatar kcaylor avatar mmellison avatar moul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eve-mongoengine's Issues

Pagination _meta

When requesting with "max_results" less than the total resources in DB, the _meta field returns an incorrect "total" value (it's the same as the "max_results" value).. Should be the total number of resources in DB.

PATCH with empty content raises OperationError

When issuing PATCH request with empty content {}, eve-mongoengine fails with

Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/vagrant/workspace/shop-demo/src/magnetpro/server/magnetpro/services/common/base.py", line 549, in catcher
    return func(*args, **kwargs)
  File "/home/vagrant/workspace/shop-demo/src/magnetpro/server/magnetpro/services/common/base.py", line 626, in proxy
    response = view(**request.view_args)
  File "/home/vagrant/workspace/shop-demo/src/magnetpro/server/magnetpro/services/menu.py", line 382, in patch
    current_app.data.update('MenuItem', _id, payload)
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/eve_mongoengine/datalayer.py", line 279, in update
    qry.update_one(write_concern=self._wc(resource), **kwargs)
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 467, in update_one
    upsert=upsert, multi=False, write_concern=write_concern, **update)
  File "/home/vagrant/.virtualenvs/shop-demo/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 423, in update
    raise OperationError("No update parameters, would remove data")
OperationError: No update parameters, would remove data

Is the project dead?

Hi all,

I was wondering whether there is any ideas of developing the project. Indeed, the requirements.txt date back to a <=0.9 version of mongoengine which is currently at its v0.10.6.
Just in case I volunteer in taking over it.

Luca

FileField

Hello,
I was wondering what the issue was with supporting the FileField? Is it on the Eve side, or is there some other issue?

I'd love to help solve this.

Thanks,
James

Connection to replica sets

The connection assumes a single host and does not accommodate the possibility of a replica set. The easiest fix would be to allow for the use of a MONGO_URI when setting up the connection, which - if set - would be used to make the connection rather than building the connection using the MONGO_HOST, and MONGO_PORT variables. If MONGO_URI is not set, then the behavior would remain as in the current implementation. Thoughts?

KeyError _etag

I am getting this exception with a simple code. It breaks the /person endpoint and all of other endpoints I receive a 404 error.

screen shot 2015-09-14 at 5 22 28 pm

Using:

  • eve 0.5.3 or in-dev

  • eve-Mongoengine 0.0.9

    class Person(mongoengine.Document):
    name = mongoengine.StringField()
    age = mongoengine.IntField()

    app = Eve()
    ext = EveMongoengine(app)
    ext.add_model(Person)

Mongoengine hooks + ETag fail

When defined some mongoengine pre_save hook, which modifies saved data (data, which are about to be saved), etag is computed from non-changed data -- FAIL. Eve-mongoengine datalayer should cover this use-case.

Requests using etag returned by POST is bound to get a 412

The etag returned by POST is inserted before the a document is saved into DB. So this etag is calculated without the _id field:
https://github.com/nicolaiarocci/eve/blob/master/eve/methods/post.py#L225
Though later there's point the document does have _id, the etag is not updated since there's already one.
https://github.com/nicolaiarocci/eve/blob/master/eve/methods/common.py#L384

If you use the returned etag here to do another request, a DELETE for example, the etag comparison is bound to fail because the server-side etag is now calculated with _id:
https://github.com/nicolaiarocci/eve/blob/master/eve/methods/common.py#L64

Example:

POST /people HTTP/1.1
Content-Type: application/json

{
    "name": "test"
}

Response:

{
    "created_at": "2015-03-26 05:55:17", 
    "updated_at": "2015-03-26 05:55:17", 
    "_links": {"self": {"href": "people/55139f45a54d75532e2ed06f", "title": "People"}}, 
    "_status": "OK", 
    "_id": "55139f45a54d75532e2ed06f", 
    "_etag": "87f7a17318bed13ba0ad0dcd259b3b22a4c9375a"
}

With the above etag:

DELETE /people/55139f45a54d75532e2ed06f HTTP/1.1
Content-Type: application/json
If-Match: 87f7a17318bed13ba0ad0dcd259b3b22a4c9375a

Now we get a 412.

Is it possible listField with Embedded fields ?

Hi,

Is it possible to implement ListField with EmbeddedField? Something:

stars = ListField(EmbeddedDocumentField(StarsModel))

where...

class StarsModel(EmbeddedDocument):
    score = db.IntField(default=0)
    voter = db.ReferenceField(User)

How to make this schema?

Deal with Document creation

Its impossible for me to create document based on Eve Mongoengine.

Because .save() is checking for existing fields and not _etag and _deleted.

If I want to have thoses two fields in my database I have to specify them in the schema, but Eve don't agree with this.

how to add put to a item or a resource.

i have tried using the item_methods=['GET', 'PUT', 'DELETE', 'PATCH' ] approach at both the resource and item level. resource level doesnt even let me add a put. python compiler throws up.

ext.add_model(Item, item_methods=['GET', 'PUT', 'DELETE', 'PATCH' ])

this succeeds but i still get a 405. in the response i see "allow:
OPTIONS, HEAD, DELETE, POST, GET" . so no put essentially.

i just want to update a record. i tried using post for it but it complains about the_id field being not present. suggestions?

No authorization support for MongoDB

I could not get my connections to work and then noticed that there is no authenticate operation even if you supply a proper MONGO_USERNAME and MONGO_PASSWORD variable.

I traced the connection to the class MongoengineDataLayer and re-wrote the start of the init to the following:

def init(self, ext):
"""
Constructor.

    :param ext: instance of :class:`EveMongoengine`.
    """

    username = ext.app.config['MONGO_USERNAME']
    password = ext.app.config['MONGO_PASSWORD']
    auth = (username, password)

    if any(auth) and not all(auth):
        raise Exception('Must set both USERNAME and PASSWORD or neither')

    self.conn = connect(ext.app.config['MONGO_DBNAME'],
                        host=ext.app.config['MONGO_HOST'],
                        port=ext.app.config['MONGO_PORT'])

    db = self.conn[ext.app.config['MONGO_DBNAME']]
    if any(auth):
        db.authenticate(username, password)

This now accounts for a passed username and password, and does connect if proper.

I would submit a patch/pull, except I dont work in indents with spacing (SCiTE autoscript saves them as TABS) so on a save it blew the diff out to every line.

HTH

ability to exclude fields using projection:{ 'field': 0}

It would be nice to be able to use Eve's projection definitions to exclude fields rather than only defining fields to include. Right now, _projection() assumes the list of keys in projection are fields to include. However,

datasource: {
    projection: { 'field': 0 }
}

should return all fields except 'field'. Perhaps a simple check on the value of keys in projection and then using either qs.only() or qs.exclude() would work?

Set default query manager attribute into datalayer class

Datalayer class should contain some attribute, which would define default queryset (query manager) attribute. Nowadays, it's objects. But one could want something else, some non-default queryset. Maybe this should work:

class MongoengineDataLayer(Mongo):
    """
    Data layer for eve-mongoengine extension.
    Most of functionality is copied from :class:`eve.io.mongo.Mongo`.
    """
    json_encoder_class = MongoengineJsonEncoder
    _structured_fields = (EmbeddedDocumentField, DictField, MapField)
    # new attribute! ------------------------------------------------------
    default_queryset_attr = 'objects'
    # ---------------------------------------------------------------------
    ....

Compatibility Problem Between Eve-Mongoengine and Eve-Swagger

The Eve-Swagger is a python library used to create swagger doc:
https://github.com/pyeve/eve-swagger

I had eve and eve-swagger working together fine. After I tried to install Eve-Mongoengine in my virtualenv, the eve-swagger produced an internal error when I tried to visit /api-docs endpoint. I've realized that there must be some version conflict between eve-swagger and Eve-Mongoengine that makes problems. It's output of eve when I tried to get /api-docs endpoint:
127.0.0.1 - - [28/Aug/2017 10:31:46] "GET /api-docs HTTP/1.1" 500 -
I tried eve in DEBUG mode and got nothing.

It's is my requirements.txt file before installing Eve-Mongoengine that was fine:
Cerberus==0.9.2
click==6.7
Eve==0.7.4
Eve-Swagger==0.0.7
Events==0.2.2
Flask==0.12
Flask-PyMongo==0.5.1
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==0.23
pymongo==3.5.0
simplejson==3.11.1
Werkzeug==0.11.15

This is my requirements.txt after installing Eve-Mongoengine that makes /api-docs unavailable:
blinker==1.4
Cerberus==0.7.2
click==6.7
Eve==0.4
Eve-Mongoengine==0.0.9
Eve-Swagger==0.0.7
Events==0.2.1
Flask==0.10.1
Flask-PyMongo==0.3.0
itsdangerous==0.24
Jinja2==2.7.3
MarkupSafe==0.23
mongoengine==0.13.0
pymongo==2.7.1
simplejson==3.5.2
six==1.10.0
Werkzeug==0.9.6

I already filed this issue in eve-swagger git project:
pyeve/eve-swagger#50

unique constraint returns 500 instead of 409

If a field has a unique constraint, Eve would return 500 if a duplicate value is submitted, instead of 409.
I think this also applies to other constraints as well, since Eve only catches exceptions raised by PyMongo, not by MongoEngine.

Is there any chance that this can be fixed?

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.