MSSQLで使用するカスタムタイプの "XMLType"を宣言しようとしています。しかし、私は'AttributeError: module 'app.db.XMLType' has no attribute '_set_parent_with_dispatch''
を得続けます。 XMLTypeクラスファイルで正しく宣言されていないものは表示されません。MSSQLでXMLのカスタムUserDefinedTypeを宣言するSQLAlchemy
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
私はhttp://docs.sqlalchemy.org/en/latest/core/custom_types.html?highlight=get_col_spec#sqlalchemy.types.UserDefinedTypeとUsing postgresql xml data type with sqlalchemyのオフコードを基づかています。
a)のフルトレースバックb)に適切な、最小限の完全かつ検証可能な例を提供してください。エラーが発生したときに、カスタムタイプをどこでどのように使用していましたか? –