DAL Bug?

68 views
Skip to first unread message

Leonel Câmara

unread,
Jul 8, 2014, 1:18:45 PM7/8/14
to web...@googlegroups.com
I noticed I was getting zero returned from my deletes. After reading the python docs I found this:

With SQLite versions before 3.6.5, rowcount is set to 0 if you make a DELETE FROM table without any condition.


Shouldn't the DAL handle this better? Maybe in SQLiteAdapter which should already have a delete method overload anyway since there's special case code for it in the BaseAdapter which shouldn't be there as special cases should be in the specific implementations.
 





Derek

unread,
Jul 8, 2014, 5:35:35 PM7/8/14
to web...@googlegroups.com
What's buggy about it? 

Leonel Câmara

unread,
Jul 9, 2014, 8:58:14 AM7/9/14
to web...@googlegroups.com
It should not return zero, it should return the number of deleted rows. The purpose of using a DAL is to abstract away this kind of differences.

Anthony

unread,
Jul 9, 2014, 10:54:27 AM7/9/14
to web...@googlegroups.com
Can you show your delete code that generated SQL without any condition?

Leonel Câmara

unread,
Jul 9, 2014, 11:15:11 AM7/9/14
to web...@googlegroups.com
The code was literally just this line:

        count = db(db.static_page.id == request.args(0)).delete()

I have no idea why the sql is going without a condition, the static page does get deleted. I only noticed the problem because the next lines were:

        if not count:
            raise HTTP(404)

And I was constantly getting a 404.

I tested this on the command line after inserting a static page

>>> db(db.static_page.id > 0).select().first()
<Row {'body': '<p>vefvefv</p>', 'lang': 'pt', 'name': 'vevefv', 'is_active': Tru
e, 'created_by': 1L, 'created_on': datetime.datetime(2014, 7, 9, 16, 8, 51), 'mo
dified_on': datetime.datetime(2014, 7, 9, 16, 8, 51), 'modified_by': 1L, 'id': 1
L}>
>>> count = db(db.static_page.id == 1).delete()
>>> count
0
>>> db(db.static_page.id > 0).select().first()
>>>

So as you can see it's returning zero when in fact it's deleting one record, as one can see in the final query that nothing is returned.

Leonel Câmara

unread,
Jul 9, 2014, 11:16:10 AM7/9/14
to web...@googlegroups.com
Humm wait a minute, could this be because I enabled versioning and nothing is in fact deleted?

Massimo Di Pierro

unread,
Jul 9, 2014, 11:33:19 AM7/9/14
to web...@googlegroups.com
yes/.That is it. Please open a ticket about this, it may be considered a bug even if we should discuss it on web2py-developers. Not so clear cut.

Leonel Câmara

unread,
Jul 9, 2014, 12:00:19 PM7/9/14
to web...@googlegroups.com
Thanks everyone for helping me sort this out, issue submitted:

lyn2py

unread,
Jul 9, 2014, 7:17:36 PM7/9/14
to web...@googlegroups.com
I ran into something similar. If you use versioning, you need to create your own function to "delete" the item, which is in fact, to just "disable" the entry and then filter all searches by excluding the "deleted" entries, otherwise it would break your foreign key links to the other (versioning) databases.

Leonel Câmara

unread,
Jul 10, 2014, 6:25:14 AM7/10/14
to web...@googlegroups.com
But lyn2pi that's what the delete is doing (marking them inactive), my only peeve is with the count returned from the delete which in my opinion should be the number of rows marked inactive.
Reply all
Reply to author
Forward
0 new messages