Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1253 (closed defect: fixed)

Opened 12 years ago

Last modified 11 years ago

SQLObject JSON Bug

Reported by: alskdj80 Owned by: anonymous
Priority: normal Milestone: 1.5
Component: SQLObject Version: 1.0
Severity: major Keywords: turbojson jsonify sqlobject
Cc:

Description

I'm pretty sure this is a bug. I only guess that it's Turbogears' bug because I just upgraded TG from 1.0b2 to 1.0, but I could be wrong. The exact same code also worked perfectly in 1.0b2, but now causes errors in 1.0.

This happens when I use the SQLObject selectBy(), but only when I use it in a JSON expose. The error I get is:

File "/usr/lib/python2.4/site-packages/SQLObject-0.7.2-py2.4.egg/sqlobject/dbconnection.py",
line 749, in assertActive assert not self._obsolete,
"This transaction has already gone through ROLLBACK;
begin another transaction"
AssertionError: This transaction has already gone through ROLLBACK; begin another transaction


My controller.py:

@turbogears.expose(format="json")
def subcategory(self, category_id):
    try:
        #return subcategories in the selected category via JSON
        subcategories = SubCategory.selectBy(categoryID=int(category_id))
    except SQLObjectNotFound:
        raise cherrypy.NotFound

    return dict(subcategories=subcategories)


My javas.js file that has the JSON callback:

    var d = loadJSONDoc("/subcategory/1?tg_format=json");

    d.addCallback(subcategoryShowResults, post_type);


The callback works perfectly, but the results received from subcategory() are not correct. So I visited /subcategory/1?tg_format=json as the URL and found the error that I posted at the beginning of this description.

However, if I change the line: subcategories = SubCategory.selectBy(categoryID=int(category_id))
to become
subcategories = SubCategory.select(SubCategory.q.categoryID == category_id)

Then everything works perfectly. I believe that these two queries should do the same thing. And I'm almost certain that in 1.0b2, this worked perfectly.

I have selectBy() in other parts of my code but not in @expose(format="json") functions. They work perfectly.

Change History

comment:1 Changed 12 years ago by alskdj80

  • Component changed from unassigned to SQLObject

comment:2 Changed 12 years ago by alberto

  • Milestone changed from 1.0.2 to 1.0.3

comment:3 Changed 12 years ago by faide

  • Milestone changed from 1.0.3 to 1.1

comment:4 Changed 11 years ago by Chris Arndt

  • Keywords turbojson jsonify sqlobject added

comment:5 Changed 11 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to fixed

This is really old, but I checked it anyway. Could not reproduce this with TG 1.0.4.4 and SO 0.9.4 (nor with SO 0.7.2). Probably it was a bug in the code or has been fixed in TG meanwhile. If you still find problems with @expose(format="json") and SO, please reopen and attach a full test case.

comment:6 Changed 11 years ago by chrisz

Addendum: Was able to reproduce this with the old TurboJson? 1.1 used before TG 1.0.3.3. Has been fixed in TurboJson? 1.1.1 (r3522). See also #1310.

Note: See TracTickets for help on using tickets.