Peewee: get() raising exception

Created on 15 Jun 2017  路  1Comment  路  Source: coleifer/peewee

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?

Most helpful comment

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

>All comments

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')
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kadnan picture kadnan  路  3Comments

MozzieHan picture MozzieHan  路  4Comments

dev-zero picture dev-zero  路  4Comments

megachweng picture megachweng  路  3Comments

mmongeon-aa picture mmongeon-aa  路  4Comments