简体   繁体   English

保存数据时出现mongokit SchemaTypeError

[英]mongokit SchemaTypeError when save data

I have a mongokit model: 我有一个mongokit模型:

class Job(Document):
    __collection__ = 'jobs'
    structure = {
        'data': dict,
        'queue': basestring,
        'executor': mongokit.OR(basestring, dict),
        'state_name': basestring,
        'state': mongokit.OR(basestring, dict),
        'inherit': basestring,
    }
    default_values = {}
    required_fields = []

When I saved data, it raised SchemaTypeError: executor must be an instance of <basestring or dict> not unicode . 当我保存数据时,它引发SchemaTypeError: executor must be an instance of <basestring or dict> not unicode

unicode is subtype of basestring . unicodebasestring子类型。 This error confused me. 这个错误使我感到困惑。

These are my dependency versions: 这些是我的依赖版本:

  • python: 2.7.10 的Python:2.7.10
  • mongokit: 0.9.1.1 mongokit:0.9.1.1

Some info about Strings in Python: 有关Python中字符串的一些信息:

Firstly, "Everything is Object in python." 首先,“ Python中的一切都是对象 ”。

Object
  1. Basestring
       1. str
       2. unicode

To make it clear for understanding: 为了使理解更清楚:

In [1]: unicode_str = u"I am unicode"
In [2]: normal_str = "I am normal string"

In [3]: isinstance(unicode_str, unicode)
Out[3]: True

In [4]: isinstance(unicode_str, str)
Out[4]: False

Moral: Type of unicode will be unicode and not basestring. 道德: Unicode的类型将是Unicode,而不是基字符串。 Hence, you are getting such error. 因此,您会收到此类错误。

So while passing a string data to field executor , cast it into string. 因此,在将字符串数据传递给字段executor ,将其转换为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM