On Sep 27, 2008, at 3:12 PM, Sean Davis wrote:

>
> I have been playing with new types using sqlalchemy and have an error
> I do not understand.  Table schema and type definition are here:
>
> -----------------------------------------
>
> def generate_uuid():
>    return uuid.uuid1()
>
> class GUID(sa.types.TypeEngine):
>    def __init__(self):
>        pass
>
>    def get_col_spec(self):
>        return "varchar(40)"
>
>    def convert_bind_param(self, value, engine):
>        return str(value)
>
>    def convert_result_value(self, value, engine):
>        return uuid.UUID(value)
>
> t_contacts = sa.Table('contacts',meta.metadata,
>    sa.Column('id',sa.types.Integer,primary_key=True),
>    sa.Column('uuid',GUID,default=generate_uuid),
>    sa.Column('firstname',sa.types.String(32),nullable=False),
>    sa.Column('lastname',sa.types.String(32),nullable=False),
>    sa.Column('email',sa.types.String(100),nullable=False),
>    sa.Column('phone',sa.types.String(32)))
>
> ----------------------------------
>
> In a Pylons web app, I get:
>
> <class 'sqlalchemy.exc.ProgrammingError'>: (ProgrammingError) can't
> adapt 'INSERT INTO contacts (id, uuid, firstname, lastname, email,
> phone) VALUES (%(id)s, %(uuid)s, %(firstname)s, %(lastname)s, %
> (email)s, %(phone)s)' {'uuid':
> UUID('58d6bcb4-8cc6-11dd-983d-0016cb972e45'), 'firstname': u'Sean',
> 'lastname': u'Davis', 'email': u'sdavis2 AT mail.nih.gov', 'phone':
> u'301-435-2652', 'id': 3L}

assuming str(UUID()) returns a string, seems like your  
convert_bind_param is not being called.   This method was deprecated  
throughout 0.4 and is removed in 0.5, so if you're on 0.5 you should  
use the bind_processor() and result_processor() methods described at 
http://www.sqlalchemy.org/docs/05/types.html 
  .




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to