A bug of Autumn

6 views
Skip to first unread message

张沈鹏

unread,
Dec 20, 2008, 11:44:01 PM12/20/08
to Autumn ORM
DROP TABLE IF EXISTS `test_zuroc`.`user_recs`;
CREATE TABLE `test_zuroc`.`user_recs` (
`user_id` int(11) NOT NULL default '0',
`cat_id` int(4) NOT NULL default '0',
`scores` varchar(5000) NOT NULL,
PRIMARY KEY (`user_id`,`cat_id`),
KEY `user_id` (`user_id`),
KEY `cat_id` (`cat_id`)
) ENGINE=MEMORY DEFAULT CHARSET=latin1;

class UserRecs(Model):

class Meta:
table = 'user_recs'

rec = UserRecs(user_id='1', cat_id='1',scores="112")
rec.save()


> "D:\dev\evn\python\python.exe" -u "D:\dev\project\eplyon\app\orm.py"
D:\dev\evn\python\lib\site-packages\MySQLdb\__init__.py:34:
DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
raw_sql: exception: not all arguments converted during string
formatting
sql: INSERT INTO `user_recs` (`user_id`, `cat_id`, `scores`) VALUES
(%s, %s)
values: ['1', '1', '112']
Traceback (most recent call last):
File "D:\dev\project\eplyon\app\orm.py", line 24, in <module>
rec.save()
File "D:\dev\evn\python\lib\site-packages\autumn\model.py", line
239, in save
self._new_save()
File "D:\dev\evn\python\lib\site-packages\autumn\model.py", line
196, in _new_save
cursor = Query.raw_sql(query, values, self.db)
File "D:\dev\evn\python\Lib\site-packages\autumn\db\query.py", line
190, in raw_sql
cursor.execute(sql, values)
File "D:\dev\evn\python\lib\site-packages\MySQLdb\cursors.py", line
151, in execute
query = query % db.literal(args)
TypeError: not all arguments converted during string formatting

I modify

def _new_save(self):
'Uses SQL INSERT to create new record'
# if pk field is set, we want to insert it too
# if pk field is None, we want to auto-create it from
lastrowid
auto_pk = 1 and (self._get_pk() is None) or 0
query = 'INSERT INTO %s (%s) VALUES (%s)' %
(self.Meta.table_safe,
', '.join([escape(f) for f in self._fields
if f != self.Meta.pk or not auto_pk]),
', '.join([self.db.conn.placeholder] * (len
(self._fields) - auto_pk)))
values = [getattr(self, f, None) for f in self._fields
if f != self.Meta.pk or not auto_pk]
cursor = Query.raw_sql(query, values, self.db)
into
def _new_save(self):
'Uses SQL INSERT to create new record'
# if pk field is set, we want to insert it too
# if pk field is None, we want to auto-create it from
lastrowid
auto_pk = 1 and (self._get_pk() is None) or 0
fileds=[escape(f) for f in self._fields if f != self.Meta.pk
or not auto_pk]
query = 'INSERT INTO %s (%s) VALUES (%s)' % (
self.Meta.table_safe,
', '.join(fileds),
', '.join([self.db.conn.placeholder] * len(fileds) )
)
values = [getattr(self, f, None) for f in self._fields
if f != self.Meta.pk or not auto_pk]
cursor = Query.raw_sql(query, values, self.db)

and the _get_pk define twice
def _get_pk(self):
'Returns value of primary key'
return getattr(self, self.Meta.pk)

def _get_pk(self):
'Sets the current value of the primary key'
return getattr(self, self.Meta.pk, None)

Jared Kuolt

unread,
Dec 22, 2008, 4:59:21 PM12/22/08
to Autumn ORM
Can you send a patch file to me? Note that there is a new repository
at Github:
http://github.com/JaredKuolt/autumn

张沈鹏

unread,
Dec 22, 2008, 7:03:24 PM12/22/08
to autum...@googlegroups.com
2008/12/23 Jared Kuolt <m...@superjared.com>:

--
ヽ∠
ヽㄊノ とス ゝ╱ヽ ヽレ
ㄖ ごエ ン ㄗ ンめ'

http://zsp.javaeye.com/

diff

张沈鹏

unread,
Dec 22, 2008, 7:13:57 PM12/22/08
to autum...@googlegroups.com
http://www.bitbucket.org
I have a suggest , use hg instead of git :)
Reply all
Reply to author
Forward
0 new messages