Skip to content

Commit

Permalink
Fix blob field hook, #1913.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Apr 26, 2019
1 parent f10c415 commit 60beb44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4426,7 +4426,10 @@ class BlobField(Field):
field_type = 'BLOB'

def _db_hook(self, database):
self._constructor = database.get_binary_type()
if database is None:
self._constructor = bytearray
else:
self._constructor = database.get_binary_type()

def bind(self, model, name, set_attribute=True):
self._constructor = bytearray
Expand Down
13 changes: 13 additions & 0 deletions tests/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,16 @@ def test_model_graph_multi_fk(self):
self.assertEqual(t1.alt.name, 'c')
self.assertEqual(t2.project.name, 'b')
self.assertEqual(t2.alt.name, 'b')


class TestBlobFieldContextRegression(BaseTestCase):
def test_blob_field_context_regression(self):
class A(Model):
f = BlobField()

orig = A.f._constructor
db = get_in_memory_db()
with db.bind_ctx([A]):
self.assertTrue(A.f._constructor is db.get_binary_type())

self.assertTrue(A.f._constructor is orig)

0 comments on commit 60beb44

Please sign in to comment.