[sqlalchemy] How to change polymorphic_identity dynamically

2013-05-06 Thread sajuptpm
Hi, * I have a table A with __mapper_args__ = {'polymorphic_on': type} * Table B C and D are inherited from A with polymorphic_identity type_b, type_c and type_d respectively I want to change the value of polymorphic_identity for an instance of class B, how do it ?? I tried like this, but

[sqlalchemy] Re: How to change polymorphic_identity dynamically

2013-05-06 Thread sajuptpm
Hi, I also tried like this, But not working instance_of_B.__mapper_args__[polymorphic_identity] = type_c DBSession.add(instance_of_B) transaction.commit(); and instance_of_B.__mapper__.polymorphic_identity = type_c DBSession.add(instance_of_B) transaction.commit(); Thanks, -- You received

Re: [sqlalchemy] Re: How to change polymorphic_identity dynamically

2013-05-06 Thread Julien Cigar
On 05/06/2013 13:46, sajuptpm wrote: Hi, I also tried like this, But not working instance_of_B.__mapper_args__[polymorphic_identity] = type_c DBSession.add(instance_of_B) transaction.commit(); and instance_of_B.__mapper__.polymorphic_identity = type_c DBSession.add(instance_of_B)

[sqlalchemy] Defining shared/inherited methods on mapped classes?

2013-05-06 Thread Michael Nachtigal
If I have several mapped classes on which I want to have defined some shared set of methods, e.g., ._todict(), how can I accomplish this (without multiple inheritance or defining them manually in each class)? I tried making the classes inherit from a shared parent class, but I receive errors

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Claudio Freire
On Thu, May 2, 2013 at 3:34 PM, Claudio Freire klaussfre...@gmail.com wrote: Without the C extension: ncalls tottime percall cumtime percall filename:lineno(function) 20811734 27.8290.000 27.8550.000 attributes.py:171(__get__) 7631984 13.5320.000 31.8510.000

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Claudio Freire
On Mon, May 6, 2013 at 1:10 PM, Claudio Freire klaussfre...@gmail.com wrote: On Thu, May 2, 2013 at 3:34 PM, Claudio Freire klaussfre...@gmail.com wrote: Without the C extension: ncalls tottime percall cumtime percall filename:lineno(function) 20811734 27.8290.000 27.855

Re: [sqlalchemy] How to change polymorphic_identity dynamically

2013-05-06 Thread Michael Bayer
On May 6, 2013, at 6:30 AM, sajuptpm sajup...@gmail.com wrote: Hi, * I have a table A with __mapper_args__ = {'polymorphic_on': type} * Table B C and D are inherited from A with polymorphic_identity type_b, type_c and type_d respectively I want to change the value of

Re: [sqlalchemy] Defining shared/inherited methods on mapped classes?

2013-05-06 Thread Michael Bayer
On May 6, 2013, at 11:55 AM, Michael Nachtigal michael.nachti...@catalinamarketing.com wrote: If I have several mapped classes on which I want to have defined some shared set of methods, e.g., ._todict(), how can I accomplish this (without multiple inheritance or defining them manually in

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Michael Bayer
that's a lot of effort there. How confident are you that memory and references are handled correctly in the .c code? That's a lot of C code, and it took years for us to iron out all the memory leaks in the existing C extensions that we had - the original author eventually stopped maintaining

RE: [sqlalchemy] Defining shared/inherited methods on mapped classes?

2013-05-06 Thread Michael Nachtigal
Thanks, your first solution was just what I needed! From: sqlalchemy@googlegroups.com [sqlalchemy@googlegroups.com] on behalf of Michael Bayer [mike...@zzzcomputing.com] Sent: Monday, May 06, 2013 12:41 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy]

[sqlalchemy] Running a trigger with sqlalchemy that works with session.execute

2013-05-06 Thread Amit Sethi
Anyone who can help out with sqlalchemy related problem I have a app which using sqlalchemy as the orm. As the app is one in transition some of the update query's run through a session.execute . However I need to create a trigger of some kind . I am trying to use MapperExtensions but it seems

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Claudio Freire
On Mon, May 6, 2013 at 1:50 PM, Michael Bayer mike...@zzzcomputing.com wrote: that's a lot of effort there. How confident are you that memory and references are handled correctly in the .c code? Quite. It's not my first C extension. But, truly, C is complex. That's a lot of C code, and it

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Michael Bayer
did you generate your code here with pyrex?If you want to jump in and rework our C extensions to be pyrex based and everything works out just as well or better than before, it'll be a great 0.9/1.0 feature.I've got a bit of experience with cython already as I've worked on lxml a bit,

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Claudio Freire
On Mon, May 6, 2013 at 2:31 PM, Michael Bayer mike...@zzzcomputing.com wrote: did you generate your code here with pyrex?If you want to jump in and rework our C extensions to be pyrex based and everything works out just as well or better than before, it'll be a great 0.9/1.0 feature.

[sqlalchemy] Descriptor being overridden because of its name?

2013-05-06 Thread Michael Nachtigal
I'm using a declarative mapping in combination with reflection, and I'm providing some custom renaming of column names in the mapped class, as demonstrated below. temp_user = self.metadata.tables['user_t'] class MappedUser(Base): __table__ = temp_user user_number = temp_user.c.user_id

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Claudio Freire
On Mon, May 6, 2013 at 2:31 PM, Michael Bayer mike...@zzzcomputing.com wrote: did you generate your code here with pyrex? Oh, sorry, I didn't answer this. No. I wrote it by hand. Pyrex-generated code is inscrutable, not that there's any need to inscrute. But really, when using pyrex, the C

[sqlalchemy] Casting an overlap filter as an array

2013-05-06 Thread Glenn Yonemitsu
Hi, all. In Postgresql I have a CMS entry model with a tag column varchar(20)[]. I want to do a query so a row with any of the tags will be returned. I know overlap is the method to use but I can't get the casting done correctly. Right now I am trying (and a lot of searching revealed similar

Re: [sqlalchemy] Descriptor being overridden because of its name?

2013-05-06 Thread Michael Bayer
not sure what you mean by descriptor here. Here's a test. show me how to reproduce the broken behavior: from sqlalchemy import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() t = Table('t', Base.metadata, Column('user_id', Integer,

RE: [sqlalchemy] Descriptor being overridden because of its name?

2013-05-06 Thread Michael Nachtigal
I was using descriptor as best I could to match its meaning as I understood it in SQLAlchemy (http://docs.sqlalchemy.org/ru/latest/glossary.html#term-descriptor), but it may be wrong. Here's how I could somewhat reproduce the error using your code (by the way, which is more appropriate for

Re: [sqlalchemy] Descriptor being overridden because of its name?

2013-05-06 Thread Michael Bayer
right that won't work. if you want that pattern, use synonym(): http://docs.sqlalchemy.org/en/rel_0_8/orm/mapper_config.html#id2 usually a hybrid is what's used here but if you really want just the alternate name, synonym will do it. short code examples inline are just fine. On May 6,

[sqlalchemy] order by on properties column

2013-05-06 Thread V'Raj Kanwade
Hi, I have 2 tables: Members GroupMembers orm.mapper(Member, meta.Members) orm.mapper(GroupMember, meta.GroupMembers properties={ 'member': orm.relation(Member, primaryjoin=meta.GroupMembers.c.memberID == meta.Members.c.id, lazy=False) } ) I want to do something like query

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Michael Bayer
Here's a ticket where we can keep talking about this: http://www.sqlalchemy.org/trac/ticket/2720 (here's the py3k ticket also: http://www.sqlalchemy.org/trac/ticket/2161) note that SQLAlchemy 0.9 will no longer use 2to3, and will by Python 2.6-3.3 in place.The enhancement here is targeted

Re: [sqlalchemy] order by on properties column

2013-05-06 Thread Michael Bayer
On May 6, 2013, at 3:21 PM, V'Raj Kanwade viraj.kanw...@gmail.com wrote: Hi, I have 2 tables: Members GroupMembers orm.mapper(Member, meta.Members) orm.mapper(GroupMember, meta.GroupMembers properties={ 'member': orm.relation(Member,

Re: [sqlalchemy] order by on properties column

2013-05-06 Thread V'Raj Kanwade
Thanks Michael On Monday, 6 May 2013 12:29:07 UTC-7, Michael Bayer wrote: On May 6, 2013, at 3:21 PM, V'Raj Kanwade viraj@gmail.comjavascript: wrote: Hi, I have 2 tables: Members GroupMembers orm.mapper(Member, meta.Members) orm.mapper(GroupMember, meta.GroupMembers

Re: [sqlalchemy] Are sqlalchemy queries a generator?

2013-05-06 Thread Claudio Freire
On Mon, May 6, 2013 at 4:27 PM, Michael Bayer mike...@zzzcomputing.com wrote: as for the __slots__ thing, that's a separate issue.if your patch doesn't break tests we can set that for 0.9 as well, I doubt anyone is subclassing InstanceState, though I'd want to see what the speedup is with

[sqlalchemy] unicode SAWarning

2013-05-06 Thread Richard Gerd Kuesters
Hi, I'm just pulling this up because it's a little anoying. Everytime I start my application, this warning shows: *[...]/lib/python2.7/site-packages/sqlalchemy/engine/default.py:471: SAWarning: Unicode type received non-unicode bind param value.** ** processors[key](compiled_params[key])* I

Re: [sqlalchemy] unicode SAWarning

2013-05-06 Thread Michael Bayer
this happens when you do this: class SomeClass(Base): # ... some_col = Column(Unicode(50)) s = SomeClass(somestring='some value') and then when you commit s to the database, the bytestring is detected and the warning emitted. Note 'some value' is a Python bytestring, not a Unicode

Re: [sqlalchemy] unicode SAWarning

2013-05-06 Thread Richard Gerd Kuesters
Thanks Mike. I know I must use unicode, and, in a matter of fact, I do respect the first item of your list. That's why I asked here :) I'll try items 2 and 5 (which seems more appropriate, since my application runs only on Postgres). Best regards, Richard. On 05/06/2013 05:50 PM, Michael

[sqlalchemy] Using a UUID as primary key

2013-05-06 Thread Wichert Akkerman
I was looking at using a UUID as primary key for a table. Using the backend-agnostic GUID type from http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#backend-agnostic-guid-type I get strange behaviour though. I whipped up a simple test case: class Data(BaseObject): __tablename__ =

[sqlalchemy] null values in multi column unique index

2013-05-06 Thread gvv
Hi All, using 8.1 class Company(Base): __tablename__ = 'Company' Id = Column(Integer, primary_key=True) class ProductClass(Base): __tablename__ = 'ProductClass' Id = Column(Integer, primary_key=True) Company_Id = Column(Integer, ForeignKey(Company.Id,

[sqlalchemy] Re: Using a UUID as primary key

2013-05-06 Thread Wichert Akkerman
For reference I have attached a complete test case including a copy of the GUID code from the documentation. On May 6, 2013, at 23:22, Wichert Akkerman wich...@wiggy.net wrote: I was looking at using a UUID as primary key for a table. Using the backend-agnostic GUID type from

Re: [sqlalchemy] Using a UUID as primary key

2013-05-06 Thread Michael Bayer
well what's happening here is fairly simple, the mapper and ORM don't know anything about the conversion from string to UUID. So when you pass it Data(uuid=some string), it persists it, passing it off to the Core which converts the UUID, but because you've supplied the primary key, it then

Re: [sqlalchemy] null values in multi column unique index

2013-05-06 Thread Michael Bayer
this depends on the database you're using, and I'd google around for stack overflow information on how to implement unique values with NULLs allowed. For example here is postgresql: http://dba.stackexchange.com/questions/9759/postgresql-multi-column-unique-constraint-and-null-values and

Re: [sqlalchemy] Using UniqueConstraint or unique=True :p:

2013-05-06 Thread Paradox
On 05/03/2013 04:18 PM, Simon King wrote: On Thu, May 2, 2013 at 11:43 PM, Paradox para...@pobox.com wrote: CREATE TABLE user (lname string, fname string, email string, unique(lname, fname) ON CONFLICT REPLACE); This will allow me to add multiple rows with the same lname as long as the fnames

[sqlalchemy] contains_eager and ordering

2013-05-06 Thread Bobby Impollonia
I am executing a query with contains_eager to load objects and their related objects from a different table. I would like to control the order of the related objects within each InstrumentedList. I had hoped this could be done through the ordering in the query. For example, with a query like:

Re: [sqlalchemy] Using a UUID as primary key

2013-05-06 Thread Lycovian
I was curious if you might elaborate on the issues with using a GUID as the primary key? I use them extensively in my professional database projects where I have multiple remote geographic sites that might have key collisions. Actually I haven't used a bigint serial PK in years and haven't