python-3.xbeaker

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


I'm calling the method invalidate() from Beaker and it's throwing the error the following error. The strange thing is that this was working correctly a few days ago, and the "attribute 'Field'" which is referenced in the error is actually a class that I recently removed from my code.

Why would Beaker throw an error referencing a class that no longer exists?

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'>

Solution

  • I was able to fix this, it turns out Beaker has a folder in which it stores the cache. Deleting the folder C:\Users\rodolfo.ortiz\Documents\Beaker\tmp\cache removed the error.

    My guess is that an old copy of the cache was being retrieved and since the model did not longer match what was in the cache, an error was being thrown. But the error is misleading because it mentions an attribute, which is actually a class.