correction, this seems to work, though will try to improve: class UUID_ARRAY(TypeDecorator): impl = ARRAY(UUID, dimensions=1)
def bind_expression(self, bindvalue): if bindvalue.callable: val = bindvalue.callable() else: val = bindvalue.value if val is None: val = [] elif not hasattr(val, '__iter__'): return bindvalue return array( cast(literal(str(uuid_val)), UUID()) for uuid_val in val ) On Jan 7, 2013, at 9:55 AM, Michael Bayer wrote: > this is ticket http://www.sqlalchemy.org/trac/ticket/2648 and cannot be > worked around at this time. If you're working with arrays of UUID I'd > recommend using psycopg2 type processors, as the previous poster has had > success with. > > > > On Jan 7, 2013, at 9:39 AM, Hans Lellelid wrote: > >> I am looking to adapt this code for a related array/type issue. The code >> from https://gist.github.com/4433940 works just fine for me (as expected) >> when building/executing the stmt directly, but not when using the ORM. >> >> When row is created using ORM, like this: >> >> # <snip> >> s = Session(bind=engine) >> e = Example() >> e.timestamp=datetime.datetime.utcnow(), >> e.num=2, >> e.guids = [uuid.uuid4(), uuid.uuid4()] >> s.add(e) >> s.commit() >> >> I get an error like this: >> >> <snip> >> return getter(visitor)(self, **kw) >> File >> "/home/hans/workspace/providence/env/lib/python2.7/site-packages/SQLAlchemy-0.8.0b2-py2.7-linux-x86_64.egg/sqlalchemy/sql/compiler.py", >> line 760, in visit_bindparam >> bind_expression = bindparam.type.bind_expression(bindparam) >> File "test_array.py", line 38, in bind_expression >> for uuid_val in val >> TypeError: 'object' object is not iterable >> >> (I can dump in full stack if that would be helpful.) >> >> Indeed, inspecting that reveals that it is simply an object() instance. I'm >> not sure where that is being set or whether there is an obvious workaround >> here. I'm sure I'm simply missing obvious when it comes to dealing with >> native array types and ORM entity instances. >> >> Thanks, >> Hans >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/sqlalchemy/-/ZwxFp2iasq0J. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.