Python + Beaker error: Can't get attribute 'MyAttribute' on <module 'classes' from c:\\Users\\Documents\\classes.py'>

Python + Beaker error: Can't get attribute 'MyAttribute' on <module 'classes' from c:\\Users\\Documents\\classes.py'>

我正在从 Beaker 调用 invalidate() 方法,它抛出了以下错误。奇怪的是,这几天前工作正常,错误中引用的 "attribute 'Field'" 实际上是我最近从代码中删除的 class。

为什么 Beaker 会抛出引用不再存在的 class 的错误?

Traceback (most recent call last):
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\flask\_compat.py", line 33, in
reraise
raise value
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\rodolfo.ortiz\Documents\test\main.py", line 25, in predict
schema_manager.invalidateCache("tenant", "schemaServiceUrl", "useLocalSchemaInfo", "useLocalValuesInfo")
  File "C:\Users\rodolfo.ortiz\Documents\test\schema_manager.py", line 31, in invalidateCache
cache.invalidate(GetSchemaAndFields, "GetSchemaAndFields", tenant, schemaServiceUrl, useLocalSchemaInfo, useLocalValuesInfo)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\cache.py", line 542, in
invalidate
_cache_decorator_invalidate(cache, key_length, args)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\cache.py", line 615, in
_cache_decorator_invalidate
cache.remove_value(cache_key)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\cache.py", line 327, in
remove_value
mycontainer.clear_value()
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\container.py", line 420, in clear_value
self.namespace.acquire_write_lock()
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\container.py", line 223, in acquire_write_lock
self.open('c', checkcount=True, replace=replace)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\container.py", line 240, in open
self.do_open(flags, replace)
  File "C:\Users\rodolfo.ortiz\.virtualenvs\test\lib\site-packages\beaker\container.py", line 673, in do_open
self.hash = pickle.load(fh)
AttributeError: Can't get attribute 'Field' on <module 'classes' from 'C:\Users\rodolfo.ortiz\Documents\test\classes.py'>

我能够解决这个问题,结果是 Beaker 有一个文件夹用于存储缓存。删除文件夹 C:\Users\rodolfo.ortiz\Documents\Beaker\tmp\cache 消除了错误。

我的猜测是正在检索缓存的旧副本,并且由于模型不再与缓存中的内容匹配,因此引发了错误。但是这个错误是有误导性的,因为它提到了一个属性,实际上是一个 class.