Thread: [SQLObject] SQLObject and Zope 2.7.3/2.8.0a1
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Anders B. O. <an...@br...> - 2004-11-26 07:53:42
|
Hi, I realize that this question may have been brought up before, but I haven't been able to find a good answer in the archives. I am trying to make a Zope product that uses SQLObject to talk to a MySQL database. In my main class (SimpleItem) I have a method called listPeople() which looks like this: def listPeople(self): """Return a list of people""" p = Backend.People.select(Backend.People.q.entity == 0) people = list() for person in list(p): people.append({"id": person.id, "name": person.name, "lived": person.lived}) return people It is called from a ZPT file to get a list of authors (it's a book database) that can be displayed. It works fine right after being added, but after refreshing the product or restarting the Zope server, I get this error whenever I try to view a page that calls that method: Error Type: AttributeError Error Value: 'NoneType' object has no attribute 'iterSelect' According to the errorlog the error occurs on the line where I do the for-loop, which means that the problem is the list(p) call. I am guessing that this is due to persistence or something like that. I thought it might be something related to cache, so I tried setting _cacheValues = False on the Backend.People class, but that didn't change anything. Can anybody help? Is it just 100% impossible to use SQLObject with Zope 2? I have tried this with both Zope 2.7.3 and 2.8.0a1 with the same results. -- Anders -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? ------END GEEK CODE BLOCK------ PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41 |
From: Oleg B. <ph...@ma...> - 2004-11-26 09:32:39
|
On Fri, Nov 26, 2004 at 08:53:32AM +0100, Anders Bruun Olsen wrote: > def listPeople(self): > """Return a list of people""" > p = Backend.People.select(Backend.People.q.entity == 0) > people = list() Why not people = [] ? > for person in list(p): > people.append({"id": person.id, "name": person.name, "lived": person.lived}) > return people > > It is called from a ZPT file to get a list of authors (it's a book > database) that can be displayed. > > It works fine right after being added, but after refreshing the product > or restarting the Zope server, I get this error whenever I try to view a > page that calls that method: > > Error Type: AttributeError > Error Value: 'NoneType' object has no attribute 'iterSelect' > > According to the errorlog the error occurs on the line where I do the > for-loop, which means that the problem is the list(p) call. I am No. .select() cannot find a module or class. > guessing that this is due to persistence or something like that. I No, this is due to problems with registries. SQLObject registries are not compatible with module reloading (refresh). > Is it just 100% impossible to use SQLObject with Zope 2? It is possible, at least in Zope3. Look at http://codespeak.net/z3/sqlos/ . May be you can port it to Zope2. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Anders B. O. <an...@br...> - 2004-11-26 11:26:51
|
On Fri, Nov 26, 2004 at 12:32:31PM +0300, Oleg Broytmann wrote: > > people = list() > Why not > people = [] > ? Readability. I like list() because it seems just a tiny bit more clear than [], even though the end result is the same. > > According to the errorlog the error occurs on the line where I do the > > for-loop, which means that the problem is the list(p) call. I am > No. .select() cannot find a module or class. Ahh.. and .select() returns None, and the list(p) then fails because list(None) does not make sense, since None is not iterable. > > guessing that this is due to persistence or something like that. I > No, this is due to problems with registries. SQLObject registries are > not compatible with module reloading (refresh). Hmm.. and I assume there is no easy way to fix that? > > Is it just 100% impossible to use SQLObject with Zope 2? > It is possible, at least in Zope3. Look at > http://codespeak.net/z3/sqlos/ . May be you can port it to Zope2. It looks really good, but I doubt that I can easily port it to Zope2, and Zope3 looks like quite a different beast than Zope2. I might end up having to just deal with SQL directly :( -- Anders -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? ------END GEEK CODE BLOCK------ PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41 |
From: Oleg B. <ph...@ma...> - 2004-11-26 11:36:13
|
On Fri, Nov 26, 2004 at 12:26:45PM +0100, Anders Bruun Olsen wrote: > On Fri, Nov 26, 2004 at 12:32:31PM +0300, Oleg Broytmann wrote: > > > people = list() > > Why not > > people = [] > > ? > > Readability. I like list() because it seems just a tiny bit more clear > than [], even though the end result is the same. Oops. My readability taste says opposite! :) I prefer [] to list(). The matter of taste... > > > According to the errorlog the error occurs on the line where I do the > > > for-loop, which means that the problem is the list(p) call. I am > > No. .select() cannot find a module or class. > > Ahh.. and .select() returns None, and the list(p) then fails because > list(None) does not make sense, since None is not iterable. Clear, but not exactly. .select() returns SelectResult, whose __iter__ returns iterSelect of its dbconnection. It seems connection object was broken or lost during refresh. > > > guessing that this is due to persistence or something like that. I > > No, this is due to problems with registries. SQLObject registries are > > not compatible with module reloading (refresh). > > Hmm.. and I assume there is no easy way to fix that? Do not use refresh. Always do full Zope restart - stop and start it anew. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Anders B. O. <an...@br...> - 2004-11-26 15:54:18
|
On Fri, Nov 26, 2004 at 02:36:07PM +0300, Oleg Broytmann wrote: > > Readability. I like list() because it seems just a tiny bit more clear > > than [], even though the end result is the same. > Oops. My readability taste says opposite! :) I prefer [] to list(). > The matter of taste... Yup! :) > > Ahh.. and .select() returns None, and the list(p) then fails because > > list(None) does not make sense, since None is not iterable. > Clear, but not exactly. .select() returns SelectResult, whose > __iter__ returns iterSelect of its dbconnection. It seems connection > object was broken or lost during refresh. Okay. > > > No, this is due to problems with registries. SQLObject registries are > > > not compatible with module reloading (refresh). > > Hmm.. and I assume there is no easy way to fix that? > Do not use refresh. Always do full Zope restart - stop and start it > anew. Same problem. Whenever Zope has been stopped my product breaks as I have described, and it needs to be added again. I have tried with "Restart" in the Zope panel and actually stopping the Zope service on the server and starting it again. -- Anders -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? ------END GEEK CODE BLOCK------ PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41 |
From: Oleg B. <ph...@ma...> - 2004-11-26 16:39:54
|
On Fri, Nov 26, 2004 at 04:54:14PM +0100, Anders Bruun Olsen wrote: > > Do not use refresh. Always do full Zope restart - stop and start it > > anew. > > Same problem. Whenever Zope has been stopped my product breaks as I have > described, and it needs to be added again. I have tried with "Restart" > in the Zope panel and actually stopping the Zope service on the server > and starting it again. Ouch! I am not sure about what caused this. My guess is that Zope or ZODB cannot unpickle connection object. I am not sure if it is possible to fix the problem. This is probably that "pickle problem" - SQLObject tables are essentially non-picklable, I am afraid. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Anders B. O. <an...@br...> - 2004-11-26 16:49:25
|
On Fri, Nov 26, 2004 at 07:39:48PM +0300, Oleg Broytmann wrote: > > Same problem. Whenever Zope has been stopped my product breaks as I have > > described, and it needs to be added again. I have tried with "Restart" > > in the Zope panel and actually stopping the Zope service on the server > > and starting it again. > Ouch! I am not sure about what caused this. My guess is that Zope or > ZODB cannot unpickle connection object. I am not sure if it is possible > to fix the problem. This is probably that "pickle problem" - SQLObject > tables are essentially non-picklable, I am afraid. Damn.. oh well, I guess it's I'm gonna have to use the MySQLdb module and do the SQL manually then :-/. Since I was planning to first learn Zope and then get a Plone site up and running for work and then integrate a few databases we have in there through Zope/Plone products, it isn't just possible for me to use something like Webware instead (which I believe I read somewhere runs sqlobject just fine). I'll have to do the manual work for now since Plone doesn't run on Zope3 yet and Zope3 seems quite a bit different from Zope2. Anyways, thank you for your help! -- Anders -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? ------END GEEK CODE BLOCK------ PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41 |
From: Anders B. O. <an...@br...> - 2004-11-26 17:03:18
|
On Fri, Nov 26, 2004 at 07:39:48PM +0300, Oleg Broytmann wrote: > Ouch! I am not sure about what caused this. My guess is that Zope or > ZODB cannot unpickle connection object. I am not sure if it is possible > to fix the problem. This is probably that "pickle problem" - SQLObject > tables are essentially non-picklable, I am afraid. WHOA! It seems I fixed it! I have in my Backend.py file not set a _connection for any of my SQLObject classes because I want to define that information directly when adding the object to Zope, and I then set it with Backend.People.setConnection and so forth in my main class's __init__. I thought I would give this one simply try to see if it was indeed just a question of restoring the connection (and without knowing whether sqlobject would indeed do what I thought it would do). I moved those .setConnection calls into a method of it's own that is called from __init__ but also from the methods that actually fetch information from SQLObject right before instantiating any SQLObject classes, and it bloody well survives both Zope restarts AND product refreshes now! I know that it might be quite an evil punch in the gut of performance for my app, but so far it is only a few people on our LAN that will use it to interact with a few databases. Later when I need to integrate those databases with a Plone site I can give some more consideration to performance and see if it does indeed hurt performance to reconnect to the db on every db-related-action. Since most normal webapps do one db-connection per page load and this will be almost the same I don't really think it will be that bad performance-wise. -- Anders -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/O d--@ s:+ a-- C++ UL+++$ P++ L+++ E- W+ N(+) o K? w O-- M- V PS+ PE@ Y+ PGP+ t 5 X R+ tv+ b++ DI+++ D+ G e- h !r y? ------END GEEK CODE BLOCK------ PGPKey: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8BFECB41 |
From: Oleg B. <ph...@ma...> - 2004-11-27 07:42:12
|
On Fri, Nov 26, 2004 at 06:03:14PM +0100, Anders Bruun Olsen wrote: > WHOA! It seems I fixed it! [skip] > Backend.People.setConnection and so forth in my main class's __init__. I Congratulations! Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |