小编Jef*_* Li的帖子

Mongoengine 0.8.0在模型中打破了我的自定义setter属性

在Mongoengine 0.7.10中,我仍然可以做以下事情:

class User(db.Document):
    email = db.EmailField(unique=True, required=True)
    _password = db.StringField(max_length=255, required=True)

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, password):
        self._password = bcrypt.generate_password_hash(password)
user = User(email='1@1.com', password='12345')
Run Code Online (Sandbox Code Playgroud)

但是,上面的代码在0.8.0中断: ValidationError: ValidationError (User:None) (_password.Field is required: ['User'])

似乎MongoEngine在启动期间无法识别我的自定义密码设置器.我必须手动编写这些来修复它:

user = User(email='1@1.com')
user.password='12345'
Run Code Online (Sandbox Code Playgroud)

这可能是由于以下变化(来自Mongonengine 0.8升级说明):

Previously, if you had data the database that wasn’t defined in the Document definition, it would set it as an attribute on the document. This is no longer the case and the data is set …

python mongoengine

8
推荐指数
2
解决办法
2311
查看次数

剖析并发现烧瓶应用的瓶颈 - 电流响应时间为30秒

我的Flask应用程序在过去一个月突然变得非常慢,我不知道哪些更改可以将响应时间从1s 提升到30s.

我一直在使用Flask和MongoEngine,Redis也用于缓存.MongoDB与Flask应用程序放在同一台服务器上.

我试过剖析Flask,这是报告:

127.0.0.1 - - [17/Feb/2014 19:51:47] "GET / HTTP/1.0" 200 -
--------------------------------------------------------------------------------
PATH: '/items'
         637497 function calls (618866 primitive calls) in 30.961 seconds

   Ordered by: internal time, call count
   List reduced from 702 to 30 due to restriction <30>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      153   30.127    0.197   30.127    0.197 {method 'recv' of '_socket.socket' objects}
   319965    0.150    0.000    0.150    0.000 {isinstance}
 1322/740    0.079    0.000    0.178    0.000 /home/deploy/shopping/env/lib/python2.7/site-packages/mongoengine/dereference.py:147(_attach_objects)
       77    0.079    0.001    0.079    0.001 {method 'sendall' …
Run Code Online (Sandbox Code Playgroud)

python profiling mongoengine flask

7
推荐指数
2
解决办法
6365
查看次数

标签 统计

mongoengine ×2

python ×2

flask ×1

profiling ×1