Bug #674
Attempting to use SmorgasbordMixin to replace connection object triggers AttributeError
Description
After attempting to use the SmorgasbordMixin and MongoMixin to replace the self.connection object in PageMaker with self.bord for my database calls, an AttributeError is triggered and a traceback is shown by the DebuggingPageMaker.
What follows is part of the debug data generated by the DebuggingPageMaker, with the line marked by DebuggingPageMaker as triggering the fault prefixed with a ">":
<type 'exceptions.AttributeError'> __exit__ Traceback (most recent call first) File: "/home/niek/Repos/floes/ads/model.py" Scope: RandomFromAdspot Source code 74 Returns an Advert object.""" 75 if isinstance(adspot, Adspot): 76 adspot = adspot.key > 77 with connection as cursor: 78 record = cursor.Execute(""" 79 SELECT advert.*, resource.adsize 80 FROM `adspot` Frame locals adspot =1 cls =<class 'floes.ads.model.Advert'> connection =<uweb.model.Smorgasbord object at 0x186d990>
The PageMaker class currently has the following subclasses defined on it in my pages.py file:
class PageMaker(uweb.pagemaker.MongoMixin,
uweb.pagemaker.SmorgasbordMixin,
uweb.DebuggingPageMaker):
Associated revisions
History
#1 Updated by Elmer de Looff almost 13 years ago
Actually, this is a core uWeb model issue that was introduced in Python2.7. This is because the with statement was changed to a single opcode
>>> from underdark.libs.sqltalk import mysql
>>> from uweb import model
>>> connection = mysql.Connec('example', 'example')
>>> bord = model.Smorgasbord()
>>> bord.AddConnection(connection, 'relational')
>>> with bord as cursor:
... cursor.Select('message')
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: __exit__
The fix for this is to add explicit __enter__
and __exit__
methods to Smorgasbord
that do The Right Thing™
#2 Updated by Elmer de Looff almost 13 years ago
- Status changed from New to Resolved
- % Done changed from 0 to 70
Applied in changeset bf1cf9c3dcb8.
#3 Updated by Elmer de Looff almost 13 years ago
- Status changed from Resolved to Closed
- % Done changed from 70 to 100
Smorgasbord Pagemaker mixin now stores connections in the local dictionary instead of passing them through every request. Also upated Smorgasbord class in the model after finding out that Python2.7 does not agree with enter and exit being returned by getattribute while not belonging to the actual object that returned them. They now cascade down to their relevant connections. This resolves #674.