Re: Delete class in model and downgrade, bulk_insert

2014-03-17 Thread Tom Haulitschke
So, create a Table, use that, make sure you’re sending the right kinds of objects to bulk_insert(). Thank you very much for that very quick reply, this did the trick. The try/except blocks in my post above were just to show what I've tried so far. I'll include my working code so that it

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Dirk Makowski
Hello Michael, On Sunday, March 16, 2014 10:19:16 PM UTC+1, Michael Bayer wrote: are you sure it’s actually saying “SET NULL” in the SQL? if the value isn’t present in the params, that just means it’s leaving it unaffected. this is normal behavior when the value hasn’t changed. I

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Dirk Makowski
A slightly improved version, where I activated the onupdate=_validate_editor() check again to log an error if it finds editor_id not set. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails

[sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Pau Tallada
Hi everyone :) I have an application with some kind of dynamic model. Several plugins define subclasses of a common base class and override their behaviour, but they do not change any column. In some scenarios, not all the puglins are loaded, so not all the subclasses are present/defined in the

Re: [sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Michael Bayer
On Mar 17, 2014, at 6:48 AM, Pau Tallada tall...@pic.es wrote: Hi everyone :) I have an application with some kind of dynamic model. Several plugins define subclasses of a common base class and override their behaviour, but they do not change any column. In some scenarios, not all the

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Michael Bayer
This is what I suggested originally, you set tn.editor_id to 2, then you run the same loop over and over again. the value of tn.editor_id does not change, and is not part of the parameters in the UPDATE statement. if you remove the column on update and look at the echoed SQL, the statements

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Dirk Makowski
So I did some debugging, the first time for me looking deeper into SA's code. Hopefully I did not get too lost. In the 3rd loop, when the loaded editor_id == 2 and was again assigned 2, I forced a flush and stepped into SA. Down the top levels I could see SA bearing a loaded_value == 2 and a

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Dirk Makowski
Wow, great explanation, thanks a lot. This also sheds light on what I had seen during the debug. On Monday, March 17, 2014 12:44:24 PM UTC+1, Michael Bayer wrote: This is what I suggested originally, you set tn.editor_id to “2”, then you run the same loop over and over again. the value of

Re: [sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Pau Tallada
Great! I think it works for my needs :D Thank you very much! Pau. 2014-03-17 12:28 GMT+01:00 Michael Bayer mike...@zzzcomputing.com: On Mar 17, 2014, at 6:48 AM, Pau Tallada tall...@pic.es wrote: Hi everyone :) I have an application with some kind of dynamic model. Several plugins

Re: [sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Pau Tallada
Hi, Can it be done in declarative? I've tried several ways, but I cannot find a working one :/ Basically, I think I need to redefine some self-referential relationships, as they link against the polymorphic class. Meta = declarative_meta() class NonPolymorphicClass(MyBaseClass):

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Dirk Makowski
sa.Column( sa.Integer(), sa.ForeignKey( pym.user.id, onupdate=CASCADE, ondelete=RESTRICT ), nullable=True, # Learned 20140317: Don't do this if you do not want to actively # set

Re: [sqlalchemy] Feedback appreciated (again :)

2014-03-17 Thread Richard Gerd Kuesters
hello! good job on these extensions and utilities. i have been using some of them, i'll give a try on the newest releases and i'll let you know. also, i forgot to contribute code with you on github. i'll send you an email directly. best regards, richard. On 03/15/2014 06:11 AM, Konsta

Re: [sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Michael Bayer
maybe make a subclass of the polymorphic base, and just put __concrete__ = True in the mapper_args.skip the non primary part. On Mar 17, 2014, at 8:45 AM, Pau Tallada tall...@pic.es wrote: Hi, Can it be done in declarative? I've tried several ways, but I cannot find a working one :/

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Michael Bayer
On Mar 17, 2014, at 8:53 AM, Dirk Makowski dirk.makow...@gmail.com wrote: On Monday, March 17, 2014 12:44:24 PM UTC+1, Michael Bayer wrote: the last moment you would have to validate what's to be sent as an UPDATE before the structure is fixed would be the before_update mapper event.The

Re: [sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Pau Tallada
Hi, I tried this, but then it selects WHERE table.type IN (NULL) :( class NonPolymorphicClass(MyBaseClass): __mapper_args__ = { 'concrete' : True } I'll try some more things, like overriding the __new__ method on the base class, to create subclasses if they are available, and

Re: [sqlalchemy] Weird update behaviour

2014-03-17 Thread Dirk Makowski
Really nice, you helped a lot. On Monday, March 17, 2014 3:48:43 PM UTC+1, Michael Bayer wrote: On Mar 17, 2014, at 8:53 AM, Dirk Makowski dirk.m...@gmail.comjavascript: wrote: On Monday, March 17, 2014 12:44:24 PM UTC+1, Michael Bayer wrote: the last moment you would have to validate

Re: [sqlalchemy] single table hierarchy: disable polymorphism and load all as base class

2014-03-17 Thread Michael Bayer
er, guessing, polymorphic_on=None also for that class? not sure of the mapper's tolerance. On Mar 17, 2014, at 12:10 PM, Pau Tallada tall...@pic.es wrote: Hi, I tried this, but then it selects WHERE table.type IN (NULL) :( class NonPolymorphicClass(MyBaseClass): __mapper_args__ = {

[sqlalchemy] outerjoin where first selected column is a literal dies with confusing error

2014-03-17 Thread Ryan Kelly
Hi: When I run the attached example, I get the following error: sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for object of type type 'NoneType' Which is a result of literal(1) appearing first in the select list. I don't particularly care than I can't order my columns

Re: [sqlalchemy] outerjoin where first selected column is a literal dies with confusing error

2014-03-17 Thread Michael Bayer
when you do outerjoin() it will try to join from the first item in the list, unless you do select_from: query(literal(), X.foo, Y.bar).select_from(X).join(Y, ) will see what can be done about the error message On Mar 17, 2014, at 2:58 PM, Ryan Kelly rpkell...@gmail.com wrote: Hi:

Re: [sqlalchemy] outerjoin where first selected column is a literal dies with confusing error

2014-03-17 Thread Michael Bayer
the error message has been improved in 9ec01ab35a / 987759aec51e (0.9 / 0.8) On Mar 17, 2014, at 4:16 PM, Michael Bayer mike...@zzzcomputing.com wrote: when you do outerjoin() it will try to join from the first item in the list, unless you do select_from: query(literal(), X.foo,

[sqlalchemy] Is knowing change history necessary to understand ORM, or I can get away without it?

2014-03-17 Thread Bao Niu
I've been reading the documentation on Using the Session -- Merging. The concept like *change history*, *history stream* occur several times. I know the history attribute is something that belongs to the *Core*. But my question is, is this really useful for learning ORM? How much knowledge

Re: [sqlalchemy] Is knowing change history necessary to understand ORM, or I can get away without it?

2014-03-17 Thread Michael Bayer
if you're talking about attribute history like attributes.get_history(MyClass.someattr) or inspect(my_object).attrs.history, that's all ORM stuff. SQLAlchemy Core (which might really be better to learn first, if you're really reading the docs cover to cover as opposed to just trying to do

[sqlalchemy] troubleshooting mapper error

2014-03-17 Thread Jonathan Vanasco
i'm updating my db code, and this popped up: InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: id() takes exactly one argument is there any way to tell where/how this got triggered? There's nothing

Re: [sqlalchemy] troubleshooting mapper error

2014-03-17 Thread Michael Bayer
its probably the Python builtin id being referenced somewhere On Mar 17, 2014, at 7:28 PM, Jonathan Vanasco jonat...@findmeon.com wrote: i'm updating my db code, and this popped up: InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of

Re: [sqlalchemy] troubleshooting mapper error

2014-03-17 Thread Jonathan Vanasco
thanks. i finally found it. i was querying TableA TableA mapped somewhere to TableB Table B had a backref on an 'id' field. that field got removed. the query on TableA triggered the error , even though I wasn't loading the 'id' field. because of how the backref was constructed, it was

[sqlalchemy] Unique Many-to-Many

2014-03-17 Thread Morgan McClure
I'm trying to make a many-to-many relationship using sqlalchemy 0.9 and postgres If I put a unique constraint on the join table, and I add a duplicate, I get an integrity error. If I change the collection class to set, it won't double commit, however a set prevents me from using things like

[sqlalchemy] order by before group by

2014-03-17 Thread Jonathan Herriott
Hi, I was creating a billing table that needs to be updated on repeated cycles as more information becomes available for a month, so I was following an Add Only scheme where I only add new rows, so we can keep track of the history of the month. Now, when I show them a list of bills for the

[sqlalchemy] Re: order by before group by

2014-03-17 Thread Jonathan Herriott
Ok, I figured it out. stmt = session.query(Bill).filter_by(account_id=id).order_by(Bill.timestamp.desc()).subquery() session.query().add_entity(Bill, alias=stmt).group_by(Bill.date_begin) On Monday, March 17, 2014 7:44:09 PM UTC-7, Jonathan Herriott wrote: Hi, I was creating a billing table

Re: [sqlalchemy] Unique Many-to-Many

2014-03-17 Thread Michael Bayer
On Mar 17, 2014, at 10:38 PM, Morgan McClure mcclure.mor...@gmail.com wrote: I'm trying to make a many-to-many relationship using sqlalchemy 0.9 and postgres If I put a unique constraint on the join table, and I add a duplicate, I get an integrity error. If I change the collection class