pg.UUID() should accept uuid()

Issue #1956 resolved
Mike Bayer repo owner created an issue

patch forthcoming

Comments (4)

  1. Former user Account Deleted

    Copied from post by Jonathan Gardner on sqlalchemy mailing list http://groups.google.com/group/sqlalchemy/browse_thread/thread/38215e14b1b89feb/570bedff1a414311?lnk=gst&q=uuid#570bedff1a414311:

    diff --git 
    a/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databas es/po 
    index 038a9e8..394c293 100755 
    --- 
    a/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databas es/postgres. 
    +++ 
    b/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databas es/postgres. 
    @@ -200,6 +200,17 @@ class PGBit(sqltypes.TypeEngine): 
     class PGUuid(sqltypes.TypeEngine): 
         def get_col_spec(self): 
             return "UUID" 
    + 
    +    def bind_processor(self, dialect): 
    +        def process(value): 
    +            return str(value) 
    +        return process 
    + 
    +    def result_processor(self, dialect): 
    +        import uuid 
    +        def process(value): 
    +            return uuid.UUID(value) 
    +        return process 
     class PGArray(sqltypes.MutableType, sqltypes.Concatenable, 
    sqltypes.TypeEngine): 
         def __init__(self, item_type, mutable=True):
    
  2. Mike Bayer reporter

    OK just for reference, here's the workaround. This ticket is targeted at 0.6 as we aren't really doing 0.5 releases at this point:

    class GUIDType(TypeDecorator):
        impl = PGUuid
    
        def process_bind_param(self, value, dialect):
            if value is None:
                return value
            else:
                return str(value)
    
        def process_result_value(self, value, dialect):
            if value is None:
                return value
            else:
                return uuid.UUID(value)
    
  3. Log in to comment