[sqlalchemy] Re: best way to query from a tuple of parameters

2015-10-27 Thread Jonathan Vanasco
Ah, sorry about that.  I (almost) always nest "or_" in "and_".  I don't 
think I've ever done the inverse!

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] TypeDecorator odd behavior

2015-10-27 Thread Uri Okrent
Hello, I've created a TypeDecorator for use with postgresql's JSON type, 
for the purpose of adapting it to sqlite and it's producing an incorrect 
bind parameter when using JSON's  column index operation.

I'm using sqlalchemy 0.9.4 (I haven't been able to install a more updated 
version as yet, but I didn't see anything mentioning behavior like this in 
the changelogs so I thought I'd ask the mailing list).

I have the following class:
class DynamicProperties(Base):
__tablename__ = 'dynamic_properties'
guid = Column(Text, primary_key=True)
dynamic_properties = Column(JSONDict)

Where JSONDict is simply this:
class JSONDict(TypeDecorator):
"""Backend-agnostic JSON type

Uses native JSON type on postgres or manually serializes/deserializes
JSON to Text on others

"""
impl = JSON

I removed the actual implementation of the TypeDecorator since this alone 
seems to be enough to trigger the issue.

If I create a query like this:
>>> q = session.query(DynamicProperties.dynamic_properties['vol_state'])
>>> q.all()

It produces this:
2015-10-28 02:51:48,445 - sqlalchemy.engine.base.Engine.db - INFO - base::
_execute_context:903 - SELECT dynamic_properties.dynamic_properties -> %(
dynamic_properties_1)s AS anon_1
FROM dynamic_properties
2015-10-28 02:51:48,445 - sqlalchemy.engine.base.Engine.db - INFO - base::
_execute_context:905 - {'dynamic_properties_1': '"vol_state"'}

It looks like the "vol_state" bind parameter is actually being serialized 
and this always produces a result of (None,) even though the 'vol_state' 
key is in the JSON dict.

If I change the Column type in the class definition from my JSONDict to 
plain old JSON:
class DynamicProperties(Base):
__tablename__ = 'dynamic_properties'
guid = Column(Text, primary_key=True)
dynamic_properties = Column(JSON)

Then the same query produces a correctly quoted bind param:
2015-10-28 02:57:05,060 - sqlalchemy.engine.base.Engine.xmsdb - INFO - base
::_execute_context:903 - SELECT dynamic_properties.dynamic_properties -> %(
dynamic_properties_1)s AS anon_1
FROM dynamic_properties
2015-10-28 02:57:05,061 - sqlalchemy.engine.base.Engine.xmsdb - INFO - base
::_execute_context:905 - {'dynamic_properties_1': 'vol_state'}

and a corresponding correct result: (u'active',).

Any clues?

TIA,
Uri

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.