[sqlalchemy] sqlalchemy exceptions
I am trying to use the following code to handle an exception in Turbogears, but it does not grab the SQLError: please note I did a: from sqlalchemy.exceptions import SQLError def save(self, name=None, email=None, password=None, password_confirm=None, **kw): try: u = User(user_name=name, display_name=name, email=email, password=password) raise redirect(/registered) except SQLError: flash(That account already exists.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Column name mapping problem in 0.3.7 (firebird)
Michael, I got some errors (NoSuchColumnError) after upgrading SA from 0.3.6 to 0.3.7 After some research in mailing list history, I found this thread [1]: I modified my sqlalchemy/databases/firebird.py : --- class FBDialect(... ... def max_identifier_length(self): return 31 ... --- And everything is fine now... [1] - http://groups.google.com/group/sqlalchemy/browse_thread/thread/bc86b6bcae3eef87/89ccecf1b17a4e51#89ccecf1b17a4e51 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: sqlalchemy exceptions
On May 8, 2007, at 1:23 PM, noah.gift wrote: I am trying to use the following code to handle an exception in Turbogears, but it does not grab the SQLError: please note I did a: from sqlalchemy.exceptions import SQLError def save(self, name=None, email=None, password=None, password_confirm=None, **kw): try: u = User(user_name=name, display_name=name, email=email, password=password) raise redirect(/registered) except SQLError: flash(That account already exists.) i think youre confusing a pattern from SQLObject here. creating a new object doesnt write any changes to the database in sqlalchemy. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Google Email Verification
Hi, I'm randomly getting InterfaceError exceptions in my app while doing a simple query.get_by(Uid=user_id) I don't even know where to start to look about this, I found nothing in the docs. Any pointers to the direction I should take? Thanks, --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Google Email Verification
Hi, Produce the simplest program you can that causes the error, then post both the code and full exception here. Paul Gambit wrote: Hi, I'm randomly getting InterfaceError exceptions in my app while doing a simple query.get_by(Uid=user_id) I don't even know where to start to look about this, I found nothing in the docs. Any pointers to the direction I should take? Thanks, --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Randomly getting InterfaceError exceptions
Produce the simplest program you can that causes the error, then post both the code and full exception here. Paul Sorry about the wrong subject in the last post. Google groups are quite annoying. This is the minimal program that causes the error: db = sa.create_engine('mysql://myuser:[EMAIL PROTECTED]/mydatabase') metadata = sa.BoundMetaData(db) def user_mapper(): '''Create the object/relational link for users''' users_table = sa.Table('Users', metadata, autoload=True) sa.orm.clear_mappers() sa.mapper(User, users_table) session = sa.create_session(bind_to=db) query = session.query(User) return session, query def authenticate(req, username, password): '''Grant access if password matches the one stored in the db''' dbsession, query = user_mapper() try: user = query.get_by(Uid=username) except sa.exceptions.SQLError, details: return Database error: %s % details else: if user == None: return print_error(req, That user does not exist!) The error I get is: Database error: (InterfaceError) (0, '') u'SELECT `Users`.`Uid` AS `Users_Uid`, `Users`.`Country` AS `Users_Country`, `Users`.`LName` AS `Users_LName`, `Users`.`Credits` AS `Users_Credits`, `Users`.`Pwd` AS `Users_Pwd`, `Users`.`PhoneNumber` AS `Users_PhoneNumber`, `Users`.`FName` AS `Users_FName`, `Users`.`MoneyBalance` AS `Users_MoneyBalance`, `Users`.`Email` AS `Users_Email` \nFROM `Users` \nWHERE `Users`.`Uid` = %s ORDER BY `Users`.`Uid` \n LIMIT 1' ['testuser'] Notice this sometimes works and sometime it doesn't. This is under mod_python with SQLAlchemy 0.3.7 in case it matters. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Randomly getting InterfaceError exceptions
On May 8, 2007, at 2:41 PM, Gambit wrote: Sorry about the wrong subject in the last post. Google groups are quite annoying. This is the minimal program that causes the error: db = sa.create_engine('mysql://myuser:[EMAIL PROTECTED]/ mydatabase') metadata = sa.BoundMetaData(db) def user_mapper(): '''Create the object/relational link for users''' users_table = sa.Table('Users', metadata, autoload=True) sa.orm.clear_mappers() sa.mapper(User, users_table) session = sa.create_session(bind_to=db) query = session.query(User) return session, query I see you are creating a Mapper in the same scope as a Session and a query. this is not the proper pattern as mappers are intended to be create-once-per-class objects (usually at the module level), whereas sessions are usually instantiated once-per-request, queries once-per- operation...so those three things do not belong together. in particular clear_mappers() is probably not threadsafe. The error I get is: Database error: (InterfaceError) (0, '') u'SELECT `Users`.`Uid` AS `Users_Uid`, `Users`.`Country` AS `Users_Country`, `Users`.`LName` AS `Users_LName`, `Users`.`Credits` AS `Users_Credits`, `Users`.`Pwd` AS `Users_Pwd`, `Users`.`PhoneNumber` AS `Users_PhoneNumber`, `Users`.`FName` AS `Users_FName`, `Users`.`MoneyBalance` AS `Users_MoneyBalance`, `Users`.`Email` AS `Users_Email` \nFROM `Users` \nWHERE `Users`.`Uid` = %s ORDER BY `Users`.`Uid` \n LIMIT 1' ['testuser'] Notice this sometimes works and sometime it doesn't. sometimes works and sometimes doesnt screams loudly of thread synchronization errors (as does InterfaceError from mysql). ensure that you arent sharing connections or sessions between concurrently executing threads. This is under mod_python with SQLAlchemy 0.3.7 in case it matters. another possibility is that the error is occuring corrresponding to it being the first thing running within an apache child process. again, properly organizing whats module-level vs. whats request level should work this out. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Randomly getting InterfaceError exceptions
Thanks for the reply. You are probably right about those things don't belonging together, it certainly makes a lot of sense now you mention it. I'll reorganize my code better and see if the errors go away. Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: sqlalchemy exceptions
On May 8, 1:58 pm, Michael Bayer [EMAIL PROTECTED] wrote: On May 8, 2007, at 1:23 PM, noah.gift wrote: I am trying to use the following code to handle an exception in Turbogears, but it does not grab the SQLError: please note I did a: from sqlalchemy.exceptions import SQLError def save(self, name=None, email=None, password=None, password_confirm=None, **kw): try: u = User(user_name=name, display_name=name, email=email, password=password) raise redirect(/registered) except SQLError: flash(That account already exists.) i think youre confusing a pattern from SQLObject here. creating a new object doesnt write any changes to the database in sqlalchemy. Your right. I wasn't sure of how much magic was occuring with Turbogears, but I really do like that I have to be explicit even inside of Turbogears. Forgive the dumb question, but what is the proper SQLAlchemy recommended way to deal with a situation like this. Should I see if the object already exists first, or be lazy and try to write to the database and attempt to catch the exception. I love to read, so if you can point me to some examples on situations like this it would be very helpful. Noah --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: sqlalchemy exceptions
Forgive the dumb question, but what is the proper SQLAlchemy recommended way to deal with a situation like this. Should I see if the object already exists first, or be lazy and try to write to the database and attempt to catch the exception. Good question. Personally I think that this Exception is common enough that you should check for it rather than catch it. But if you stick with what you have, I believe you will catch the error by adding something like this in your try statement: session.save(u) session.flush() I love to read, so if you can point me to some examples on situations like this it would be very helpful. Not sure if this is what you mean, but here is a very good SA tutorial: http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: sqlalchemy exceptions
On May 8, 2007, at 5:45 PM, noah.gift wrote: On May 8, 1:58 pm, Michael Bayer [EMAIL PROTECTED] wrote: On May 8, 2007, at 1:23 PM, noah.gift wrote: I am trying to use the following code to handle an exception in Turbogears, but it does not grab the SQLError: please note I did a: from sqlalchemy.exceptions import SQLError def save(self, name=None, email=None, password=None, password_confirm=None, **kw): try: u = User(user_name=name, display_name=name, email=email, password=password) raise redirect(/registered) except SQLError: flash(That account already exists.) i think youre confusing a pattern from SQLObject here. creating a new object doesnt write any changes to the database in sqlalchemy. Your right. I wasn't sure of how much magic was occuring with Turbogears, but I really do like that I have to be explicit even inside of Turbogears. Forgive the dumb question, but what is the proper SQLAlchemy recommended way to deal with a situation like this. Should I see if the object already exists first, or be lazy and try to write to the database and attempt to catch the exception. I love to read, so if you can point me to some examples on situations like this it would be very helpful. Well, my style would be to just query the database first, then if row exists just report to the user. since if you wait for an exception, you have to inspect the exception itself to check that its the key already exists error...and those errors will be different depending on the particular database in use. Unfortuantely DBAPI doesnt specify any standardized way to get at error codes and SA doesnt have any kind of error categorizing logic...so its a little bit of a guessing game. also you might want to have several operations related to creating a new user all within a single transaction which means catching the exception also means you have to roll back the transaction, making it more inconvenient to use exception catching as a check if the user exists type of function. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---