Peewee: BlobField cannot be used with uninitialized Proxy

Created on 11 May 2016  路  3Comments  路  Source: coleifer/peewee

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

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexlatchford picture alexlatchford  路  4Comments

rayzorben picture rayzorben  路  4Comments

kadnan picture kadnan  路  3Comments

lucasrc picture lucasrc  路  5Comments

kalimalrazif picture kalimalrazif  路  3Comments