4
저는 postgresql 데이터베이스에 xml
을 사용하고 있습니다. SQLAlchemy에 xml
데이터를 처리 할 수있는 사용자 정의 유형이 필요합니다.SQLAlchemy TypeDecorator가 작동하지 않습니다
그래서 xml.etree
과 통신하는 XMLType
클래스를 만들었지 만 원하는대로 작동하지 않습니다.
import xml.etree.ElementTree as etree
class XMLType(sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.types.UnicodeText
type = etree.Element
def get_col_spec(self):
return 'xml'
def bind_processor(self, dialect):
def process(value):
if value is not None:
return etree.dump(value)
else:
return None
return process
def process_result_value(self, value, dialect):
if value is not None:
value = etree.fromstring(value)
return value
그것은 검색 값과 결과 처리에 잘 작동 :
은 내가 쓴 코드를 here`s. 내가 행을 삽입하려고 할 때하지만, 내가 (물론, 나는body
xml.etree.ElementTree.Element
로 객체를 넣어) 오류가 발생합니다 :
IntegrityError: (IntegrityError) null value in column "body" violates not-null
constraint "INSERT INTO comments (id, author_id, look_id, body, created_at)
VALUES (nextval('object_seq'), %(author_id)s, %(look_id)s, %(body)s, now())
RETURNING comments.id" {'body': None, 'author_id': 1550L, 'look_id': 83293L}
이 body
값이 None
것을보고, 그것은 바인딩 프로세서가 작동하지 않는 것이 명백하다 맞아,하지만 제대로 구현 한 것 같아 상황을 바꾸려면 어떻게해야할지 모르겠다.
process_bind_param
같은 오류가 발생합니다.
어디에서 코드가 잘못 되었습니까?
고맙습니다. SQLAlchemy의 문제가 아니라 내 무지였다. :-) – yoloseem
@HyunjunKim [faq # howtoask]를 읽는 것이 좋습니다. –
오, 나는 '받아 들여진 대답'기능이 있다는 것을 몰랐습니다. 방금 했어. 이해해 주셔서 감사합니다. – yoloseem