简体   繁体   English

更新时出现Peewee异步意外关键字

[英]Peewee async unexpected keyword when updating

While using peewee async, got an error when trying to update an object: 使用peewee异步时,尝试更新对象时出现错误:

Traceback (most recent call last):
  File "./src/models/module.py", line 74, in run
    await self._stage_alert_attach(target_alert)
  File "./src/models/module.py", line 293, in _stage_alert_attach
    await target_alert.attach(unattached_issues)
  File "./src/models/alert.py", line 127, in attach
    await issue.attach(self)
  File "./src/models/issue.py", line 81, in attach
    await self.async_save()
  File "./src/models/base.py", line 40, in async_save
    return await self._manager.update(self, only=self.dirty_fields)
  File "/usr/local/lib/python3.6/site-packages/peewee_async.py", line 227, in update
    query = obj.update(**field_dict).where(obj._pk_expr())
TypeError: update() got an unexpected keyword argument 'alert_id'

I can't figure out what's happening because the field is defined in the base class: 我无法弄清楚发生了什么,因为该字段是在基类中定义的:

class BaseIssue(BaseModel):
    # Database fields
    id = peewee.PrimaryKeyField()
    module_id = peewee.IntegerField()
    model = peewee.CharField(index=True)
    model_id = peewee.CharField(index=True)
    status = peewee.CharField(index=True)
    metadata = JSONField()
    alert_id = peewee.IntegerField(null=True)
    created_at = peewee.DateTimeField(default=datetime.datetime.now)
    solved_at = peewee.DateTimeField(null=True)
    expired_at = peewee.DateTimeField(null=True)

    class Meta:
        def db_table_func(model_cls): return "Issues"

Also tried to use alert instead of alert_id and using it as a foreign key, but got the same error (now with the alert keyword). 还尝试使用alert而不是alert_id并将其用作外键,但是得到了相同的错误(现在带有alert关键字)。

I think there might be a problem with inheritance, as this base class is inherited to create an DefaultIssue class that will be inherited again. 我认为继承可能会有问题,因为继承了此基类以创建将再次继承的DefaultIssue类。 For some reason the update() method is not expecting this parameter. 由于某种原因, update()方法不需要此参数。

Here's a print of the object __dict__ and fields right before the self.async_save() call: 这是self.async_save()调用之前的对象__dict__和字段的打印:

>>> obj.__dict__

{
  "_data": {
    "created_at": datetime.datetime(2017, 10, 10, 17, 6, 8, 47075),
    "id": 2,
    "module_id": 3,
    "model": "transaction",
    "model_id": "23765771",
    "status": "active",
    "metadata": {
      "transaction_id": 23765771,
      "boleto_url": None,
      "boleto_barcode": None
    },
    "alert_id": None,
    "solved_at": None,
    "expired_at": None
  },
  "_dirty": set(),
  "_obj_cache": {},
  "_logger": <Logger Issue 2 (INFO)>
}

>>> obj._meta.fields

{
  "id": <peewee.PrimaryKeyField object at 0x7f49fdb2e198>,
  "module_id": <peewee.IntegerField object at 0x7f49fdb2e3c8>,
  "model": <peewee.CharField object at 0x7f49fdb2e710>,
  "model_id": <peewee.CharField object at 0x7f49fdb2e7f0>,
  "status": <peewee.CharField object at 0x7f49fdb2e860>,
  "metadata": <playhouse.postgres_ext.JSONField object at 0x7f49fdb2e8d0>,
  "alert_id": <peewee.IntegerField object at 0x7f49fdb2e940>,
  "created_at": <peewee.DateTimeField object at 0x7f49fdb2e9b0>,
  "solved_at": <peewee.DateTimeField object at 0x7f49fdb2ea20>,
  "expired_at": <peewee.DateTimeField object at 0x7f49fdb2ea90>
}

If there's any more information I can provide, ask please. 如果我可以提供更多信息,请询问。 I don't know what to do anymore. 我不知道该怎么办了。

Ok, I'm so stupid. 好吧,我很傻。 Just noticed I've overriden the update method. 只是注意到我已经覆盖了update方法。

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

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