[Sqlalchemy-tickets] Issue #3855: Comparator on Variant field (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Jiří K. <iss...@bi...> - 2016-11-18 15:09:35
|
New issue 3855: Comparator on Variant field https://bitbucket.org/zzzeek/sqlalchemy/issues/3855/comparator-on-variant-field Jiří Kunčar: The comparator factory for Variant field doesn't lookup the engine specific implementation. ```python @property def comparator_factory(self): """express comparison behavior in terms of the base type""" return self.impl.comparator_factory ``` I would expect something like: ```python @property def comparator_factory(self): """express comparison behavior in terms of the base type""" return self.load_dialect_impl(FIXME).comparator_factory ``` There is a workaround which more or less works for me but it is not ideal: ```python TestJSONType = sa.JSON().with_variant( postgresql.JSONB(), 'postgresql' ).with_variant( mysql.JSON(), 'mysql' ) class TestJSON(db.Model): __tablename__ = 'test_json' pk = sa.Column(sa.Integer, primary_key=True) js = sa.Column(TestJSONType) ``` ```python from werkzeug.local import LocalProxy def variant_comparator(column): """Dialect specific comparator.""" return column.type.load_dialect_impl( db.engine.dialect ).comparator_factory(column) TestJSON.js.comparator = LocalProxy(lambda: variant_comparator(TestJSON.js)) ``` |