Re: [sqlalchemy] Re: polymorphic identity after_delete event

2015-09-16 Thread Jakub Bąk
Thanks a lot! It works but I still have a problem. I want to make one query to get the root directory, all its children and the filenames of Image objects. My directory model looks like this: class Directory(Node): is_root = db.Column(db.Boolean, default=False) children =

[sqlalchemy] Mixed data type for a column

2015-09-16 Thread Mattias Lagergren
Hi, I have a table (variable_value) with a "value" column where I store a mix of data (float, boolean, datetime) as strings. On a related table the type is stored and now I'm trying to create a new calculated column "casted_value" that casts the value column to the correct type in SQL (I'm

[sqlalchemy] There is any chance to SQLAlchemy works with syncio?

2015-09-16 Thread Johnny W. Santos
Hi guys, I would like to know if theres is any chances to SQLAlchemy support asyncio out of the box? Like the ORM and such. Thanks Johnny -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails

Re: [sqlalchemy] There is any chance to SQLAlchemy works with syncio?

2015-09-16 Thread Mike Bayer
On 9/16/15 10:17 AM, Johnny W. Santos wrote: Hi guys, I would like to know if theres is any chances to SQLAlchemy support asyncio out of the box? Like the ORM and such. Well the "real" answer is "yes", which is that you'd put your ORM business logic in a threadpool using

Re: [sqlalchemy] Re: polymorphic identity after_delete event

2015-09-16 Thread Mike Bayer
On 9/16/15 5:28 AM, Jakub Bąk wrote: Thanks a lot! It works but I still have a problem. I want to make one query to get the root directory, all its children and the filenames of Image objects. My directory model looks like this: | classDirectory(Node): is_root

Re: [sqlalchemy] Mixed data type for a column

2015-09-16 Thread Mike Bayer
On 9/16/15 6:46 AM, Mattias Lagergren wrote: The important part is the casting inside of the case expression: | dynamic_cast=sqlalchemy.sql.expression.case( [ ( variable_register.c.type =='number', sqlalchemy.cast(variable_value.c.value,types.Numeric)

Re: [sqlalchemy] There is any chance to SQLAlchemy works with syncio?

2015-09-16 Thread Johnny W. Santos
Thanks for your lightning fast reply! Actually my interest in asyncio is guided pretty much because I'm using autobahn to do non-blocking websocket stuffs and and since it uses asyncio I thought it would be seamless if I could use it to handle DB non-blocking operations too. I'll take a look at

[sqlalchemy] migrating from backref to back_populates -- advice?

2015-09-16 Thread Jonathan Vanasco
I'm about to migrate about 70 relationships from backref to back_populates so the model reads cleaner/better documented.. Most are straightwordard, but a handful are more complex -- order_by or uselist are on the backref, or there may be a handful of args or primaryjoin on the relationship.

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-16 Thread Mike Bayer
OK, new day, new perspectives. This is the best way to do the mapping / type: class CastToIntegerType(TypeDecorator): impl = String def column_expression(self, col): return cast(col, Integer) def process_bind_param(self, value, dialect): return str(value) class

Re: [sqlalchemy] migrating from backref to back_populates -- advice?

2015-09-16 Thread Jonathan Vanasco
On Wednesday, September 16, 2015 at 4:14:35 PM UTC-4, Michael Bayer wrote: > > maybe you can run through all the mappings with a script and produce a > textfile indicating the settings for all the relationships. then you can > verify that the back_populates code change produces the same

[sqlalchemy] most correct way to get the columns in an object?

2015-09-16 Thread Jonathan Vanasco
given the object `source`, these both work cols = [c.key for c in list(source.__table__.columns)] cols = [c.name for c in sqlalchemy.orm.class_mapper(source.__class__).mapped_table.c] I'm sure there are other ways. is there an ideal / canonical way of getting this data?

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-16 Thread Katie Wurman
This is a perfectly usable solution. Thanks so much! On Wednesday, September 16, 2015 at 11:39:57 AM UTC-7, Michael Bayer wrote: > > OK, new day, new perspectives. This is the best way to do the mapping / > type: > > class CastToIntegerType(TypeDecorator): > impl = String > > def

Re: [sqlalchemy] migrating from backref to back_populates -- advice?

2015-09-16 Thread Mike Bayer
maybe you can run through all the mappings with a script and produce a textfile indicating the settings for all the relationships. then you can verify that the back_populates code change produces the same thing. On 9/16/15 3:47 PM, Jonathan Vanasco wrote: I'm about to migrate about 70

Re: [sqlalchemy] most correct way to get the columns in an object?

2015-09-16 Thread Mike Bayer
On 9/16/15 4:30 PM, Jonathan Vanasco wrote: given the object `source`, these both work cols = [c.key for c in list(source.__table__.columns)] cols = [c.name for c in sqlalchemy.orm.class_mapper(source.__class__).mapped_table.c] I'm sure there are other ways. is

Re: [sqlalchemy] most correct way to get the columns in an object?

2015-09-16 Thread Jonathan Vanasco
Thanks. For this bit of code, I just need the column names. We ran into an edge-case during some new tests where instead of having one of a read-through cache object (a dogpile managed dict!) a hot SqlAlchemy object got used. This bit of code just cleans up and reformats some column data

[sqlalchemy] possible bug/docs deficiency on classes with multiple identical relationships

2015-09-16 Thread Jonathan Vanasco
This drove me crazy for an hour today, until I finally figured out what was going on. I have a class with a few relationships: class Foo(base): # relationships have a prefix that describe the relation l_ (list) or o_ (scalar) l_Bars = relationship("Bars")

Re: [sqlalchemy] AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

2015-09-16 Thread Mike Bayer
check out this case, this is one way to reproduce that: https://bitbucket.org/zzzeek/sqlalchemy/issues/3532/detect-property-being-assigned-to-more On 9/15/15 3:56 PM, dewey wrote: I'll see if I can reproduce this in a simple example.it's currently in a job being run every night from a

Re: [sqlalchemy] AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

2015-09-16 Thread dewey
Hey Mike, I've found and fixed (with help) my problem, but I thought I'd describe it here to support anyone else who hits this... Was not a threading issue..it was a combination of: - data-edge case - bug in our code - bug in how SA was reporting a failure... I was adding a

Re: [sqlalchemy] possible bug/docs deficiency on classes with multiple identical relationships

2015-09-16 Thread Jonathan Vanasco
On Wednesday, September 16, 2015 at 6:56:20 PM UTC-4, Michael Bayer wrote: > > OK, what's great here is (in keeping with bugs are always reported in > twos, no matter how long theyve been around) that someone just hit this > yesterday: > Ha! I missed reading that one! this should

Re: [sqlalchemy] possible bug/docs deficiency on classes with multiple identical relationships

2015-09-16 Thread Mike Bayer
On 9/16/15 5:49 PM, Jonathan Vanasco wrote: This drove me crazy for an hour today, until I finally figured out what was going on. I have a class with a few relationships: class Foo(base): # relationships have a prefix that describe the relation l_ (list) or o_ (scalar)