"Zope DB instance has no attribute 'lock'"
I installed the Z MySQL Database Adaptor product and configured a connection with the simple 'database username password' connection string. Now I get the above when I try "select * from applicants" in the 'test' view of my database adaptor. I have no idea what it means, or how to troubleshoot it. Is the problem in my database? In Zope? WTF? The database connections shows itself as 'open', so I think it can talk to the database okay. What do I do next? I'd post more information but I'm not sure what information is necessary... Here is the traceback from the error message page's source HTML: <!-- Traceback (innermost last): File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 223, in publish_module File /usr/share/zope/lib/python/Products/Localizer/__init__.py, line 53, in new_publish File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 187, in publish File /usr/share/zope/lib/python/Zope/__init__.py, line 226, in zpublisher_exception_hook (Object: MySQL_database_connection) File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 175, in publish File /usr/share/zope/lib/python/Zope/__init__.py, line 240, in commit File /usr/share/zope/lib/python/ZODB/Transaction.py, line 325, in commit File /usr/share/zope/lib/python/Shared/DC/ZRDB/TM.py, line 122, in tpc_finish File /usr/share/zope/lib/python/Products/ZMySQLDA/db.py, line 351, in _finish AttributeError: (see above) --> ...and some other stuff: [dereks@dev dereks]$ rpm -qa | grep MySQL MySQL-client-3.23.41-5mdk MySQL-python-0.9.1-1py2 MySQL-shared-3.23.41-5mdk MySQL-3.23.41-5mdk [dereks@dev dereks]$ rpm -qa | grep Z Zope-2.4.3-1 Zope-zserver-2.4.3-1 [dereks@dev dereks]$ cat /usr/share/zope/lib/python/Products/ZMySQLDA/VERSION.txt ZMySQLDA 2.0.9 Any help would be greatly appreciated. Thanks, Derek Simkowiak
Derek Simkowiak wrote:
I installed the Z MySQL Database Adaptor product and configured a connection with the simple 'database username password' connection string.
Now I get the above when I try "select * from applicants" in the 'test' view of my database adaptor. I have no idea what it means, or how to troubleshoot it. Is the problem in my database? In Zope? WTF? The database connections shows itself as 'open', so I think it can talk to the database okay.
It sounds like a glitch in the DA.
What do I do next? I'd post more information but I'm not sure what information is necessary... Here is the traceback from the error message page's source HTML:
<!-- Traceback (innermost last): File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 223, in publish_module File /usr/share/zope/lib/python/Products/Localizer/__init__.py, line 53, in new_publish File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 187, in publish File /usr/share/zope/lib/python/Zope/__init__.py, line 226, in zpublisher_exception_hook (Object: MySQL_database_connection) File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 175, in publish File /usr/share/zope/lib/python/Zope/__init__.py, line 240, in commit File /usr/share/zope/lib/python/ZODB/Transaction.py, line 325, in commit File /usr/share/zope/lib/python/Shared/DC/ZRDB/TM.py, line 122, in tpc_finish File /usr/share/zope/lib/python/Products/ZMySQLDA/db.py, line 351, in _finish AttributeError: (see above)
-->
...and some other stuff:
I'd say, open up Products/ZMySQLDA/db.py, line 351, and it probably does something like something = somethingelse._lock If you change that to something = getattr(somethingelse, "_lock", 0) it will probably work OK. Alternatively, delete and recreate the DA object. -- Matt Kromer Zope Corporation http://www.zope.com/
-> It sounds like a glitch in the DA. Well, this is what I found. The attribute "lock" is being accessed in the _abort method, which is: -------------------------------------- def _abort(self, *ignored): try: self.db.query("ROLLBACK") self.db.store_result() finally: self.lock.release() -------------------------------------- It's failing in the finally: block, trying to access self.lock.release(). But this is all I see in the __init__ method of the class DB(TM): definition: self._lock = allocate_lock() In fact, I see this "self._lock" attribute, *with the underscore*, seven other times in the the file. But I see a self.lock attribute appear three times in the file -- but never in the __init__ method. So, as I understand it, unless self.lock appears in the __init__ method of the parent class "TM", then "self.lock" is a typo and should be "self._lock". Is that a valid assumption? Notice that TM does not declare self.lock: [root@dev ZRDB]# pwd /usr/share/zope/lib/python/Shared/DC/ZRDB [root@dev ZRDB]# grep -i lock TM.py [root@dev ZRDB]# Should I change those three instances of self.lock to be self._lock? Also, what is the last known *WORKING* version of the Z MySQL Database Adapter? This seems like a showstopper bug, but it's in a product that has to be pretty popular... -> Alternatively, delete and recreate the DA object. This I do not understand. How would simply deleting and re-creating an instance fix a bug in the code? Thanks, Derek
Derek Simkowiak wrote:
-> It sounds like a glitch in the DA.
Well, this is what I found. The attribute "lock" is being accessed in the _abort method, which is: -------------------------------------- def _abort(self, *ignored): try: self.db.query("ROLLBACK") self.db.store_result() finally: self.lock.release() --------------------------------------
I'd say it badly wants to be self._lock then... I dont think it matters so long as it is consistent.
Also, what is the last known *WORKING* version of the Z MySQL Database Adapter? This seems like a showstopper bug, but it's in a product that has to be pretty popular...
Did you download this from SourceForge? I dont know what Andy has been modifying of late, but I am very surprised that you're having problems with what appears to be an attribute name mismatch.
-> Alternatively, delete and recreate the DA object.
This I do not understand. How would simply deleting and re-creating an instance fix a bug in the code?
Well, I made a guess that the __init__ method would do the right thing, but the rest of the code wouldn't be able to tell that new attributes did not exist if the code had been upgraded, thus if you had OldDA which had no _lock attribute, but NewDA which did, if the code was upgraded from old to new, the DA object would be used in the new context without the new data. In those cases a delete/recreate usually cleans things up. -- Matt Kromer Zope Corporation http://www.zope.com/
-> Should I change those three instances of self.lock to be -> self._lock? More info: doing this fixed my problem. I am shocked and amazed that a product that *must* be one of the most popular around could have a typo in it (assuming, of course, that this is the Correct Fix for this particular problem). What's worse, this bug was caused by another (imho) "bug", see below for details. What am I missing? Did I install an unstable beta release? This is version 2.0.9, the latest I could find. I was recommending Zope + MySQL as a solution for my client, but these basic, rudimentary errors are changing my mind. Version 2.0.9 and not even the fscking "test" page works... what is up with that? Thanks, Derek P.S.> What was happening: I was testing with the string SELECT * FROM applicants; This results in an exception, caused by (imho) another "bug" in the database adapter. It limits the number of results to 1000 on SELECT for whatever reason -- but when it adds the LIMIT code, it does not remove the ";" at the end. Here is the relevant code: if qtype == "SELECT" and max_rows: qs = "%s LIMIT %d" % (qs,max_rows) r=0 db.query(qs) This results in an SQL code error, ala this result: Error Value: (1064, "You have an error in your SQL syntax near '; LIMIT 1000' at line 1") So changing my test string from "select * from applicants;" to "select * from applicants" fixed my problem. I assume I'll have a similar problem when I write my Z SQL method. Anyway, the SQL sytax error resulted in an exception, which resulted in a call to _abort(), which tried to access self.lock (instead of self._lock). Thank god I've been working with Python lately. This and stories of severe memory corruption in Zope 2.4.3 are highly disturbing.
Derek Simkowiak wrote:
-> Should I change those three instances of self.lock to be -> self._lock?
More info: doing this fixed my problem. I am shocked and amazed that a product that *must* be one of the most popular around could have a typo in it (assuming, of course, that this is the Correct Fix for this particular problem).
What's worse, this bug was caused by another (imho) "bug", see below for details.
[...]
SELECT * FROM applicants;
This results in an exception, caused by (imho) another "bug" in the database adapter. It limits the number of results to 1000 on SELECT for whatever reason -- but when it adds the LIMIT code, it does not remove the ";" at the end. Here is the relevant code:
if qtype == "SELECT" and max_rows: qs = "%s LIMIT %d" % (qs,max_rows) r=0 db.query(qs)
Well, for what its worth, Andy made those changes to the DA based on some stability feedback I'd given him, and because he probably didn't get a whole lot of people testing the beta, it slipped through. I know I make errors like this from time to time (the primary code path works but a secondary code path never is exercised). Also, I dont think any of the Zope DAs do the right thing when you suffix the SQL command terminator to a command. Granted, I think they should tolerate it, but they don't have to. This has to do with the fact that most of the program APIs to databases do NOT use a semicolon in their API calls, only the bare statement is used. I'd dearly love to see a re-implementation of Zope's RDBMS core interfaces, but this is not a trivial undertaking, and without a customer-funded requirement, Zope Corporation is not likely to perform that task. I find there to be some troubling semantic issues with only exposing the API interface "query" from a connection object. Still, not so troubling that I feel motivated to turn it in to an after-hours rewrite. -- Matt Kromer Zope Corporation http://www.zope.com/
-> Well, for what its worth, Andy made those changes to the DA based on -> some stability feedback I'd given him, and because he probably didn't -> get a whole lot of people testing the beta, it slipped through. Okay, I've calmed down now. I apologize for my earlier outburst. After RTFM'ing Z SQL Methods, and seeing that they are not supposed to have ';' at the end, I guess that is not really a problem in the MySQL adapter. And if there were no beta testers who caused _abort() to get called, this bug could easily have slipped through. So this is not as serious as it seemed. (Although why a global substition of self.lock for self._lock wasn't done, I'll never know :) Thank you Matthew for your help. I would appreciate it if you could forward on this bug to the MySQL Database Adapter maintainer. --Derek
On Mon, 4 Mar 2002, Derek Simkowiak wrote:
I installed the Z MySQL Database Adaptor product and configured a connection with the simple 'database username password' connection string.
Now I get the above when I try "select * from applicants" in the 'test' view of my database adaptor. I have no idea what it means, or how to troubleshoot it. Is the problem in my database? In Zope? WTF? The database connections shows itself as 'open', so I think it can talk to the database okay.
What do I do next? I'd post more information but I'm not sure what information is necessary... Here is the traceback from the error message page's source HTML:
<!-- Traceback (innermost last): File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 223, in publish_module File /usr/share/zope/lib/python/Products/Localizer/__init__.py, line 53, in new_publish File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 187, in publish File /usr/share/zope/lib/python/Zope/__init__.py, line 226, in zpublisher_exception_hook (Object: MySQL_database_connection) File /usr/lib/python2.1/site-packages/ZPublisher/Publish.py, line 175, in publish File /usr/share/zope/lib/python/Zope/__init__.py, line 240, in commit File /usr/share/zope/lib/python/ZODB/Transaction.py, line 325, in commit File /usr/share/zope/lib/python/Shared/DC/ZRDB/TM.py, line 122, in tpc_finish File /usr/share/zope/lib/python/Products/ZMySQLDA/db.py, line 351, in _finish AttributeError: (see above)
-->
No idea, don't use MySQLFolder. Did want to say that exUserFolder, which is similar but includes properties & caching, and can use many backends, works out of the box with MySQL for authentication. (It says its only for PostgreSQL, and if you want to store new attributes, you'll have to tweak the SQL slightly for MySQL, but for usernames/passwords/roles, it works fine w/o changes). The nice thing about exUserFolder is that if/when you switch databases/switch to LDAP/switch to SMB authentication/whatever, it will still be there for you. -- Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
-> No idea, don't use MySQLFolder. This is for the MySQL Database Adapter, not user authentication. --Derek
-> to troubleshoot it. Is the problem in my database? In Zope? WTF? The -> database connections shows itself as 'open', so I think it can talk to the -> database okay. More info: I am able to 'browse' the database --including the applicants table-- without any problems. Has anyone seen this before? Google finds nothing. Thanks, Derek
participants (3)
-
Derek Simkowiak -
Joel Burton -
Matthew T. Kromer