python - sqlalchemy truncated labels -


i trying pass dictionary returned sql-alchemy query twisted perspective broker, following error:

unpersistable('unpersistable data: instance of class sqlalchemy.sql.elements._truncated_label deemed insecure')

and while investigating found out query returns following:

<class 'sqlalchemy.sql.elements._truncated_label'> labels

can explains me how avoid ?

here 1 of table declarations:

module_tbl = table(     "module",     metadata(),     column("id", integer(), primary_key=true),     column("name", string()),     column("description", string()),     column("context", integer()),     column("scope", integer()),     column("send_body", boolean()),     column("direction", integer()),     column("level", integer()),     column("incoming_order", integer()),     column("outgoing_order", integer()),     column("created_at", datetime()),     column("updated_at", datetime()), ) 

and here code faulting:

@inlinecallbacks def get_config(mname, domains, direction):     engine = yield get_default_engine()      # try retrieve module database model, raise on fail     mod_tbl = getattr(ddl, mname + '_tbl')     if mod_tbl none:         raise modulebindexception('could not find database model module <%s>' % mname)      # convert domains list     if not isinstance(domains, list):         domains = [domains]      _select = [ddl.domain_module_tbl, ddl.domain_tbl, ddl.module_tbl, mod_tbl]     _from = ddl.domain_module_tbl     _join = [(ddl.domain_tbl, ddl.domain_module_tbl.c.domain_id ==               func.coalesce(ddl.domain_tbl.c.master_domain_id, ddl.domain_tbl.c.id)),              (mod_tbl, ddl.domain_module_tbl.c.id == mod_tbl.c.domain_module_id),              (ddl.module_tbl, ddl.domain_module_tbl.c.module_id == ddl.module_tbl.c.id), ]     _where = [ddl.domain_module_tbl.c.enabled == 1,               ddl.domain_module_tbl.c.direction.op('&')(direction),               ddl.module_tbl.c.name == mname,  # optional enforces security on blind join               ddl.domain_tbl.c.name.in_(tuple(domains))]      j in _join:         _from = _from.join(*j)      _stmt = select(_select).select_from(_from)     w in _where:         _stmt = _stmt.where(w)      # use aliasing     _stmt = _stmt.apply_labels()      # query     result = yield engine.execute(_stmt)     config = yield result.fetchall()     config_per_domain = dict()     mod_prefix = '%s_' % mname     c in config:         # rename mod_{name}_* keys mod_* it's easier access modules         cfg = dict((k, v) k, v in dict(c).items() if not k.startswith(mod_prefix))         mod_cfg = dict((str('mod_%s' % k[len('%s_' % mname):]), v) k, v in dict(c).items()                        if k.startswith(mod_prefix))         cfg.update(mod_cfg)         config_per_domain[cfg.get('domain_name')] = cfg      defer.returnvalue(config_per_domain) 

_truncated_label subclass of unicode (or str in python 3). if library using written properly, use isinstance , not type() check whether string.

anyway, subclass used names of columns, indexes , similar db objects, , when need use names in own code can use unicode(whatever) instead of whatever convert plain unicode object (str if using python 3).


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -