This is my code:
# -*- coding: utf-8 -*-
from peewee import *
from playhouse.sqlite_ext import SqliteExtDatabase
__database_file__ = 'test.db'
database = SqliteExtDatabase(__database_file__)
class TestModelDB(Model):
class Meta:
database = database
class TestDB(TestModelDB):
k = TextField(null=False, unique=True)
v = TextField(null=False)
database.connect()
database.create_tables([TestDB])
tdb = TestDB()
with database.transaction():
tdb.create(k='key1', v='value1')
tdb.get(tdb.k == 'key1')
This give next traceback witn python 2.7 and last peewee release:
Traceback (most recent call last):
File "C:/git/get_peewee.py", line 25, in <module>
tdb.get(tdb.k == 'key1')
File "C:\Python27\lib\site-packages\peewee.py", line 4926, in get
return sq.get()
File "C:\Python27\lib\site-packages\peewee.py", line 3179, in get
clone = self.paginate(1, 1)
File "C:\Python27\lib\site-packages\peewee.py", line 397, in inner
clone = self.clone() # Assumes object implements `clone`.
File "C:\Python27\lib\site-packages\peewee.py", line 2771, in clone
return self._clone_attributes(query)
File "C:\Python27\lib\site-packages\peewee.py", line 3008, in _clone_attributes
query = super(SelectQuery, self)._clone_attributes(query)
File "C:\Python27\lib\site-packages\peewee.py", line 2775, in _clone_attributes
query._where = self._where.clone()
AttributeError: 'bool' object has no attribute 'clone'
get() shortcut is broken? Or maybe I'm doing something wrong?
You're working with an instance but the get() method is a class-method. So:
with database.transaction():
TestDB.create(k='key1', v='value1')
tdb = TestDB.get(TestDB.k == 'key1')
Most helpful comment
You're working with an instance but the
get()method is a class-method. So: