[sqlalchemy] Creating a custom type

2008-12-21 Thread Kless
I'm trying to build a custom type [1] to manage the bcrypt hashes [2]. --- from bcrypt_wrap import password from sqlalchemy import types class Bcrypt(types.TypeDecorator): Stores a bcrypt hash of a password. impl = types.String #(60) hasher = password.Password() def

[sqlalchemy] Re: Creating a custom type

2008-12-21 Thread Michael Bayer
On Dec 21, 2008, at 6:53 AM, Kless wrote: I'm trying to build a custom type [1] to manage the bcrypt hashes [2]. --- from bcrypt_wrap import password from sqlalchemy import types class Bcrypt(types.TypeDecorator): Stores a bcrypt hash of a password. impl = types.String

[sqlalchemy] Re: Creating a custom type

2008-12-21 Thread Kless
Thank you for detailed answer. Here are any thoughts: 1) The before_insert was being omitted while I was inserting records using an insert statement --that's logical because it was bypassing the ORM--. 2) It's necessary to use *session.commit()* after of each record because else it will have

[sqlalchemy] Re: Creating a custom type

2008-12-21 Thread Michael Bayer
oh, yeah for that recipe you'd have to use a flag on the mapper() called batch=False.But don't use that, its inefficient. So you can also create your type to detect a special value from the mapper extension: def before_insert(self, ): instance.password = (instance.password,

[sqlalchemy] retrying queries and 'Lost connection to MySQL server'

2008-12-21 Thread Bobby Impollonia
I occasionally have a query fail with 'Lost connection to MySQL server during query' which gets converted into a sqlalchemy.exceptions.OperationalError. I have not been able to figure out why it happens, but the server should always be available. I would like to tell sqlalchemy that if a query

[sqlalchemy] Re: retrying queries and 'Lost connection to MySQL server'

2008-12-21 Thread Michael Bayer
On Dec 21, 2008, at 11:24 PM, Bobby Impollonia wrote: I occasionally have a query fail with 'Lost connection to MySQL server during query' which gets converted into a sqlalchemy.exceptions.OperationalError. I have not been able to figure out why it happens, but the server should always be

[sqlalchemy] Re: retrying queries and 'Lost connection to MySQL server'

2008-12-21 Thread Bobby Impollonia
This code isn't using transactions so retrying a failed query should be as simple as creating a new connection to replace the failed one and executing the query again. Still, I would much prefer to figure out the real cause, as you say. I had sort of given up on that because after a little while