gpt4 book ai didi

python - 在 Model.get_by_id() 上出现 "Expected string, got None"错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:11:00 25 4
gpt4 key购买 nike

运行此代码时,使用相同的 site_id:

int_id= int(self.request.get("site_id"))
site_draft = SiteDraft.get_by_id(int_id)

我收到这个错误:

INFO     2016-06-27 12:39:19,040 module.py:788] minisites: "GET /edit/5891733057437696 HTTP/1.1" 500 -
return self.handle_exception(e, self.app.debug)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
return method(*args, **kwargs)
File "C:\Users\Yuri\Documents\WiseStamp\Server\minisites\web\pages\edit_site.py", line 21, in get
self.post(args)
File "C:\Users\Yuri\Documents\WiseStamp\Server\minisites\web\pages\edit_site.py", line 44, in post
site_draft = SiteDraft.get_by_id(int_id)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\utils.py", line 160, in positional_wrapper
return wrapped(*args, **kwds)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 3602, in _get_by_id
return cls._get_by_id_async(id, parent=parent, **ctx_options).get_result()
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\tasklets.py", line 378, in get_result
self.check_success()
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\tasklets.py", line 425, in _help_tasklet_along
value = gen.send(val)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\context.py", line 765, in get
pbs = entity._to_pb(set_key=False).SerializePartialToString()
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 3167, in _to_pb
prop._serialize(self, pb, projection=self._projection)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1422, in _serialize
values = self._get_base_value_unwrapped_as_list(entity)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1192, in _get_base_value_unwrapped_as_list
wrapped = self._get_base_value(entity)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1180, in _get_base_value
return self._apply_to_values(entity, self._opt_call_to_base_type)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1352, in _apply_to_values
value[:] = map(function, value)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1234, in _opt_call_to_base_type
value = _BaseValue(self._call_to_base_type(value))
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1255, in _call_to_base_type
return call(value)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1331, in call
newvalue = method(self, value)
File "C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\ext\ndb\model.py", line 1781, in _validate
(value,))
BadValueError: Expected string, got None

它曾经在一天前工作,但现在只有 20% 的时间工作(这也很奇怪 - 它似乎有时工作)。更奇怪的是,我提供了一个 int 作为 site_id,但它告诉我它得到了一个 None

请指教。

最佳答案

根据要求

详细查看堆栈跟踪并注意执行的操作,

我们看到了

 _get_by_id
get_result
_help_tasklet_al
get
_to_pb
_serialize
_get_base_value
_get_base_value
_apply_to_values
_opt_call_to_base
_call_to_base_type
call
_validate


BadValueError: Expected string, got None

我们看到执行路径在 _get_by_id 里面,它正在处理 get_result。因此已检索到一个实体。进一步往下看,我们看到代码实际上正在验证检索到的值,但在 _validate 调用中失败并返回 BadValueError: Expected string, got None

一个人如何在现有实体中获得错误的值(value)。通常,这是由于更改模型而造成的,您要么

  • 添加了一个新的必需属性并且不更新现有实体。
  • 更改了现有属性的类型
  • 向属性添加验证器,但不使现有实体合规。

当您更改模型时,考虑实体迁移很重要。

干杯

T

关于python - 在 Model.get_by_id() 上出现 "Expected string, got None"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38050616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com