BlobField determines its binary type on its initialization. BlobField then cannot be used with Proxied database that is not initialized. An AttributeError is risen right after module execution/import.
Reproducer:
import peewee
class NonWorkingBlobFieldOnProxy(peewee.Model):
class Meta:
database = peewee.Proxy()
myblob = peewee.BlobField()
Raises:
Traceback (most recent call last):
File "proxy_example.py", line 3, in <module>
class NonWorkingBlobFieldOnProxy(peewee.Model):
File "venv/lib/python2.7/site-packages/peewee.py", line 4479, in __new__
field.add_to_class(cls, name)
File "venv/lib/python2.7/site-packages/peewee.py", line 1081, in add_to_class
self._constructor = model_class._meta.database.get_binary_type()
File "venv/lib/python2.7/site-packages/peewee.py", line 407, in __getattr__
raise AttributeError('Cannot use uninitialized Proxy.')
AttributeError: Cannot use uninitialized Proxy.
This affects version 2.8.1. In later versions (2.6.X) this problem did not occur.
Commit that introduced this regression: b32e967e
Nice catch and fantastic issue report. I'll work on a solution.
Thank you. I resolved it with lazy imports, right after Proxy initialization.
The proxy should have a way to attach callbacks if I remember correctly, so I just need to move the binary type binding to a hook. I'll fix it regardless, but glad you're not blocked at the moment.
Most helpful comment
The proxy should have a way to attach callbacks if I remember correctly, so I just need to move the binary type binding to a hook. I'll fix it regardless, but glad you're not blocked at the moment.