switch all together to char as postgres is failing
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from typing import Any, Optional, Union
|
from typing import Any, Optional, Union
|
||||||
|
|
||||||
from sqlalchemy.dialects.postgresql import UUID as psqlUUID
|
|
||||||
from sqlalchemy.engine.default import DefaultDialect
|
from sqlalchemy.engine.default import DefaultDialect
|
||||||
from sqlalchemy.types import CHAR, TypeDecorator
|
from sqlalchemy.types import CHAR, TypeDecorator
|
||||||
|
|
||||||
@ -29,10 +28,7 @@ class UUID(TypeDecorator): # pragma nocover
|
|||||||
return ret_value
|
return ret_value
|
||||||
|
|
||||||
def load_dialect_impl(self, dialect: DefaultDialect) -> Any:
|
def load_dialect_impl(self, dialect: DefaultDialect) -> Any:
|
||||||
if dialect.name == "postgresql":
|
return dialect.type_descriptor(CHAR(32))
|
||||||
return dialect.type_descriptor(psqlUUID())
|
|
||||||
else:
|
|
||||||
return dialect.type_descriptor(CHAR(32))
|
|
||||||
|
|
||||||
def process_bind_param(
|
def process_bind_param(
|
||||||
self, value: Union[str, int, bytes, uuid.UUID, None], dialect: DefaultDialect
|
self, value: Union[str, int, bytes, uuid.UUID, None], dialect: DefaultDialect
|
||||||
@ -41,19 +37,13 @@ class UUID(TypeDecorator): # pragma nocover
|
|||||||
return value
|
return value
|
||||||
elif not isinstance(value, uuid.UUID):
|
elif not isinstance(value, uuid.UUID):
|
||||||
value = self._cast_to_uuid(value)
|
value = self._cast_to_uuid(value)
|
||||||
if dialect.name == "postgresql":
|
return "%.32x" % value.int
|
||||||
return str(value)
|
|
||||||
else:
|
|
||||||
return "%.32x" % value.int
|
|
||||||
|
|
||||||
def process_result_value(
|
def process_result_value(
|
||||||
self, value: Optional[str], dialect: DefaultDialect
|
self, value: Optional[str], dialect: DefaultDialect
|
||||||
) -> Optional[uuid.UUID]:
|
) -> Optional[uuid.UUID]:
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
if dialect.name == "postgresql":
|
if not isinstance(value, uuid.UUID):
|
||||||
return uuid.UUID(value)
|
return uuid.UUID(value)
|
||||||
else:
|
return value
|
||||||
if not isinstance(value, uuid.UUID):
|
|
||||||
return uuid.UUID(value)
|
|
||||||
return value
|
|
||||||
|
|||||||
Reference in New Issue
Block a user