zsql returning no results crashes dtml-call

Bug #639597 reported by Jeff Kunce
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SQLAlchemy DA
Fix Committed
Medium
Abdul Kader Maliyakkal

Bug Description

If I have a dtml statement like:
  <dtml-call "myzsqlmethod()">
and myzsqlmethod returns no results,
then I get this error:
  Error Type: TypeError
  Error Value: object of type 'NoneType' has no len()

This is only for zsql that returns "no results" (for example, an UPDATE statement), as opposed to a query that returns an empty list of rows.

I can trace the problem to SAWrapper.query() in SQLAlchemyDA.da, specifically, the lines:
        if desc is None:
            return [], None
The DocumentTemplate code (somewhere in cDocumentTemplate) wants to compute the len() of the second item in that returned tuple, which raises the error.

I couldn't find an official API for database adapters, but http://www.zope.org/Members/petrilli/WritingADA suggests that the second item in the returned tuple should be a list. If I change the code to:
            return [], []
then it works. But I don't know if anything else relies on None in that spot to signify a query with no results.

I'm open to any sort of fix or workaround. Thanks!

SQLAlchemyDA 0.5.0 (but 0.5.1 has the same issue)
sqlalchemy-0.6.4-py2.6.egg
DocumentTemplate-2.13.1
zope2-2.13.0a4

Changed in zope-sqlalchemy-da:
assignee: nobody → Abdul Kader Maliyakkal (akm-mail)
status: New → Incomplete
status: Incomplete → Confirmed
Changed in zope-sqlalchemy-da:
status: Confirmed → Fix Committed
importance: Undecided → Medium
Revision history for this message
BradAllen (brad-allendev) wrote :

I spoke with Kader and he said it was a one line change.

--- Products/SQLAlchemyDA/da.py (revision 119836)
+++ Products/SQLAlchemyDA/da.py (working copy)
@@ -207,7 +207,7 @@
        LOG.debug('Execution time: %3.3f seconds' % (time.time() - ts_start))

        if desc is None:
- return [], None
+ return [], []

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.