I am trying to declare a custom type of "XMLType" for use with MSSQL. But I keep getting 'AttributeError: module 'app.db.XMLType' has no attribute '_set_parent_with_dispatch''
. I don't see anything that isn't declared correctly in my XMLType class file.
import sqlalchemy.types as types
from lxml import etree
class XMLType(types.UserDefinedType):
def get_col_spec(self):
return 'XML'
def bind_processor(self, dialect):
def process(value):
if value is not None:
if isinstance(value, str):
return value
else:
return etree.tostring(value)
else:
return None
return process
def result_processor(self, dialect, coltype):
def process(value):
if value is not None:
value = etree.fromstring(value)
return value
return process
I am basing the code off of http://docs.sqlalchemy.org/en/latest/core/custom_types.html?highlight=get_col_spec#sqlalchemy.types.UserDefinedType and Using postgresql xml data type with sqlalchemy.