[sqlalchemy] Re: SQL echoing?
set metadata.engine.echo=False ? which revision are u using? eventuly check for remaining print's somewhere: grep -R ^ *print /sqlalchemy or grep -R ^[^#]*print /sqlalchemy One of my scripts keeps printing out a bunch of LAZY CLAUSE statements and I'd like to know how to turn that off. Here's what I'm doing: db = create_engine(settings.db_string) session = create_session(bind_to=db) cur_article = session.query(Article).selectfirst(Section.c.keyword==section, order_by=[desc(Article.c.timestamp)]) This is likely a dumb question, but I couldn't figure it out on my own. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Object-oriented engine?
how much OO u want? There is SA, which has ORM layer over sql, so can become a somewhat object persistency. There are turboentity/activemapper, currently joining together, which are simple declarative layer on top of SA. Then here is this 'sawrapper' of mine, which is also declarative and wider/deeper than them, automaticaly handling all inheritances / decomposition and references and now able to convert plain python funcs (of your objects) into SA clauses. It may join the above 2 one day - if they wish. Then i have another layer on top which adds protocol-like static-type semantics... http://linuxteam.sistechnology.com/o2rm/sawrap0209.tar.bz2 None of them is 100% OO. For a simple OOdbs, check http://www.garret.ru/~knizhnik/compare.html Has anyone tried making an engine for an OODB? My company is heavily ties into Versant, and we'd love to use SQLAlchemy if possible. Is this even a valid thought? Versant doesn't support SQL, most of its calls are graph navigation. getchild(), getparent(), getattr() etc... Is this worth pursuing, and has anyone tried it? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Object-oriented engine?
svilen wrote: how much OO u want? He's not using a DBMS. He has more OO-ness than SA could give him :-) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: improving connection resiliency
I am wondering if there isn't a better way to handle connection issues than how I am doing it (see the sample below)? You should give a try with SA 0.3.3 (at least), since several connection problems have been solved. See thread MySQL has gone way. Although it talks about MySQL, the bugfix is about the connection pool/object: http://groups.google.com/group/sqlalchemy/browse_thread/thread/9412808e695168ea/93ac328e84206c4b More precisely, also have a look at this thread How to regenerate connections in the QueuePool. You'll find a test case which reconnects/regenerates connections when the database goes down: http://groups.google.com/group/sqlalchemy/browse_thread/thread/f8f5a86ed26d19a7/857f4c70371ea96d FWIW, you'll find a example of retry mechanism which handle database recovering (well, actually, this code is not that clean...). Finally, IIRC, be aware databases exceptions encapulsation into SA's exception has been improved since 0.2.8: some weren't caught resulting in a raise of the original, underlying database exceptions. Hope it helps, Cheers Seb -- Sébastien LELONG sebastien.lelong[at]sirloon.net --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Dynamically adding MapperExtension
question. Lets say I have a series of table definitions, and a series of objects linked to the tables with a bunch of mappers. First question: Is there a way to get from the table definitions in the metadata to the Mapper? Second question: If I create a MapperExtension, can I then link it to the mapper associated with a table? What I want to do is create a simple application that goes through the tables defined within a metadata, and create an extension so that every time a table entry is added it prints 'hello world' to the screen. TIA -chris --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: FlushError: Can't change the identity of instance
svilen wrote: somehow u've managed to have 2 copies of same persistent-object - which should not happen; how did u get it? one has unicode-string '6', another one has int 6 instead - some conversion failing? ughno!! stop answering all these questions with the wrong answersit means the primary key attributes on a *single* instance have been changed since it was last saved/loaded. SA cant handle changes to the primary key attributes on a single instance within the session - see the FAQ page on the site for more information. Could please, someone tell me what the following error means? FlushError: Can't change the identity of instance [EMAIL PROTECTED] in session (existing identity: (class 'sicer.model.fatturazione.Prestazione', (6,), None); new identity: (class 'sicer.model.fatturazione.Prestazione', (u'6',), None)) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Adding with (nolock) to all queries (mssql)
before I read the next 10 replies in this thread, this seems like an issue of too high of a transaction isolation level going on (something that plagued my SQL server apps when i was writing them, though that was years ago). cant the connection itself have a more lenient isolation level set ? Arnar Birgisson wrote: Hi all, I'm using SA to build queries (no orm) and handle connection pooling on a linux machine, connecting to mssql via freetds. This was working very well with SQL Server 2000, but a couple of weeks ago we upgraded to 2005. Since then the SA app has been having some problems. I've checked that I'm using the latest (0.64) version of freetds - which was released to provide support for sql server 2005. Now, I won't go into the specific problems (mainly b/c I'm not sure what's going on) but my dba suggested that I add with (nolock) after each table alias in every query (I'm only doing selects). The problem is that the queries are built and executed with SA. Can I plug into some hooks or something to do this? Arnar --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: new setuptools vs local SA copy
I have a directory on my laptop which looks like this: ./sa026 ./sa027 ./sa028 ./sa030 ./sa031 ... I set PYTHONPATH to ./lib. I change into each directory and run a script that id like to compare between versions. No setup.py develop is required...i dont want to install anything anywhere. I just want to use *this source code right here*, even though an egg version of that software happens to be installed somewhere. I dont see why thats so unreasonable. basically right now, once you install something via setup.py, you can never ever again use any module with that same name without going through setuptools hoops for it (or shove a sys.path.insert() in your program, or hack your python like i did). Kumar McMillan wrote: put a file -pythonpath.pth into your site_packages folder: import os, sys; sys.__egginsert=len(os.environ.get('PYTHONPATH', '').split(os.pathsep)); duly noted for future usage _when_ i meet an egg. workingenv, as Simon King mentioned, is the way to go. At my company we share a dev server which has lots of stuff complied for us but for true isolated development, each developer needs his own python sandbox to make egg links to all modules in progress. $ sudo easy_install workingenv.py $ python -m workingenv --site-packages ~/temp-py $ source ~/temp-py/bin/activate and now you can run `python setup.py develop` without sudo on any package and it will only be available in that env, with a fallback to site-packages for modules you haven't installed. And of course you can have as many of these as you want. Some things I've run into... when setuptools gets upgraded (why a workingenv feature isn't built into setuptools, who knows) sometimes you need to remove the setuptools egg and rebuild your workingenv the same way you built it $ python -m workingenv --site-packages ~/temp-py this will not disturb any eggs or egg-links in your env. The only alternative (quoted above) that I know is to hack your python install (which I also did before workingenv). I still find workingenv easier, tho not ideal. I should also note that this was a perfect way to set up multiple buildbot builders on our server. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Dynamically adding MapperExtension
percious wrote: question. Lets say I have a series of table definitions, and a series of objects linked to the tables with a bunch of mappers. First question: Is there a way to get from the table definitions in the metadata to the Mapper? not conveniently. you could loop through the dictionary of mappers in sqlalchemy.orm.mapperlib.mapper_registry and just look at all the mapped_table attributes of those mappers. or just track yourself. Second question: If I create a MapperExtension, can I then link it to the mapper associated with a table? MapperExtensions currently like to be set at the time of mapper construction. there is also a way to say query.options(extension(someext)), but theres a pending ticket which is needed for some fixes to that...also that only sets an extension that takes place within the realm of a select. What I want to do is create a simple application that goes through the tables defined within a metadata, and create an extension so that every time a table entry is added it prints 'hello world' to the screen. yah that pattern is not really supported. tables/mappers/etc like to be constructed and then not changed after that, so if you cant apply your hello world function at table/mapper construction time, the closest thing you could do is either use a customized logging stream to trap INSERT statements, or if you used DynamicMetaData you could have it connect() to a ProxyEngine instance which does similar. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: new setuptools vs local SA copy
python setup.py develop [1] doesn't install anything. It makes a link to a directory of source code, just like you are doing w/ the pythonpath, and you only have to run it once. either method is accomplishing the same thing. I just find workingenv very easy to use and wanted to share since there isn't really any documentation on it. [1] http://peak.telecommunity.com/DevCenter/setuptools#develop-deploy-the-project-source-in-development-mode On 2/9/07, Michael Bayer [EMAIL PROTECTED] wrote: I have a directory on my laptop which looks like this: ./sa026 ./sa027 ./sa028 ./sa030 ./sa031 ... I set PYTHONPATH to ./lib. I change into each directory and run a script that id like to compare between versions. No setup.py develop is required...i dont want to install anything anywhere. I just want to use *this source code right here*, even though an egg version of that software happens to be installed somewhere. I dont see why thats so unreasonable. basically right now, once you install something via setup.py, you can never ever again use any module with that same name without going through setuptools hoops for it (or shove a sys.path.insert() in your program, or hack your python like i did). Kumar McMillan wrote: put a file -pythonpath.pth into your site_packages folder: import os, sys; sys.__egginsert=len(os.environ.get('PYTHONPATH', '').split(os.pathsep)); duly noted for future usage _when_ i meet an egg. workingenv, as Simon King mentioned, is the way to go. At my company we share a dev server which has lots of stuff complied for us but for true isolated development, each developer needs his own python sandbox to make egg links to all modules in progress. $ sudo easy_install workingenv.py $ python -m workingenv --site-packages ~/temp-py $ source ~/temp-py/bin/activate and now you can run `python setup.py develop` without sudo on any package and it will only be available in that env, with a fallback to site-packages for modules you haven't installed. And of course you can have as many of these as you want. Some things I've run into... when setuptools gets upgraded (why a workingenv feature isn't built into setuptools, who knows) sometimes you need to remove the setuptools egg and rebuild your workingenv the same way you built it $ python -m workingenv --site-packages ~/temp-py this will not disturb any eggs or egg-links in your env. The only alternative (quoted above) that I know is to hack your python install (which I also did before workingenv). I still find workingenv easier, tho not ideal. I should also note that this was a perfect way to set up multiple buildbot builders on our server. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Dynamically adding MapperExtension
question. Lets say I have a series of table definitions, and a series of objects linked to the tables with a bunch of mappers. First question: Is there a way to get from the table definitions in the metadata to the Mapper? For simple table==class, the link is 1:1. For multi-table-inheritances/ single-inheritances, it's many:1. And the linking is mostly the other way (mapper-to-tables, not tables-to-mappers), so u may have to dig: u can use either m=class_mapper( yourclas) or m=object_mapper( obj); then check isinstance( m.localtable, Table), and use it... all mappers are in mapper_registry... but this is all pure gymnastics... Second question: If I create a MapperExtension, can I then link it to the mapper associated with a table? themapper.extension = yours... ; or see global_extensions. dontknow about their compilation though... What I want to do is create a simple application that goes through the tables defined within a metadata, and create an extension so that every time a table entry is added it prints 'hello world' to the screen. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Dynamically adding MapperExtension
I should add that you *can* be more creative, and construct each mapper with a MapperExtension at the beginning which later can be enabled with a hello world callable. i.e. class MyExt(MapperExtension): def __init__(self): self.func = None def after_insert(self, ...): if self.func: self.func() extension = MyExt() mapper(foo, bar, extension=extension) mapper(foo2, bar2, extension=extension) mapper(foo3, bar3, extension=extension) ... do stuff ... def helloworld(): print hello world extension.func = helloworld ... do stuff ... percious wrote: question. Lets say I have a series of table definitions, and a series of objects linked to the tables with a bunch of mappers. First question: Is there a way to get from the table definitions in the metadata to the Mapper? Second question: If I create a MapperExtension, can I then link it to the mapper associated with a table? What I want to do is create a simple application that goes through the tables defined within a metadata, and create an extension so that every time a table entry is added it prints 'hello world' to the screen. TIA -chris --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Object-oriented engine?
Thanks for the tips, however I mean this DB we have is pure objects, there are no tables. So there isn't much of a logical leap to strap python on top of it, however you can't use and SQL. I guess I was wondering how tied to SQL SA is? If it's fundamental to the core, then I'm out of luck. But it different engines can supply their own navigation logic, then it might be worthwhile. On Feb 9, 12:16 am, svilen [EMAIL PROTECTED] wrote: how much OO u want? There is SA, which has ORM layer over sql, so can become a somewhat object persistency. There are turboentity/activemapper, currently joining together, which are simple declarative layer on top of SA. Then here is this 'sawrapper' of mine, which is also declarative and wider/deeper than them, automaticaly handling all inheritances / decomposition and references and now able to convert plain python funcs (of your objects) into SA clauses. It may join the above 2 one day - if they wish. Then i have another layer on top which adds protocol-like static-type semantics...http://linuxteam.sistechnology.com/o2rm/sawrap0209.tar.bz2 None of them is 100% OO. For a simple OOdbs, checkhttp://www.garret.ru/~knizhnik/compare.html Has anyone tried making an engine for an OODB? My company is heavily ties into Versant, and we'd love to use SQLAlchemy if possible. Is this even a valid thought? Versant doesn't support SQL, most of its calls are graph navigation. getchild(), getparent(), getattr() etc... Is this worth pursuing, and has anyone tried it? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Object-oriented engine?
Thanks for the tips, however I mean this DB we have is pure objects, there are no tables. so u have to define the O-to-R mapping of your objects into tables, then ... So there isn't much of a logical leap to strap python on top of it, however you can't use and SQL. I guess I was wondering how tied to SQL SA is? If it's fundamental to the core, then I'm out of luck. But it different engines can supply their own navigation logic, then it might be worthwhile. do u mean to make a Versant-alchemy? That is, something that looks more like a language and less like bunch of lowlevel getattr/getparents()-calls? i guess u'll have to make it on your own... btw There was some versant python wrapper here, ancient (1999): http://starship.python.net/crew/jmenzel/ The link maybe dead, i have the .tgz (37K) if u want it as starting point. On Feb 9, 12:16 am, svilen [EMAIL PROTECTED] wrote: how much OO u want? There is SA, which has ORM layer over sql, so can become a somewhat object persistency. There are turboentity/activemapper, currently joining together, which are simple declarative layer on top of SA. Then here is this 'sawrapper' of mine, which is also declarative and wider/deeper than them, automaticaly handling all inheritances / decomposition and references and now able to convert plain python funcs (of your objects) into SA clauses. It may join the above 2 one day - if they wish. Then i have another layer on top which adds protocol-like static-type semantics...http://linuxteam.sistechnology.com/o2rm/sawrap0209.ta r.bz2 None of them is 100% OO. For a simple OOdbs, checkhttp://www.garret.ru/~knizhnik/compare.html Has anyone tried making an engine for an OODB? My company is heavily ties into Versant, and we'd love to use SQLAlchemy if possible. Is this even a valid thought? Versant doesn't support SQL, most of its calls are graph navigation. getchild(), getparent(), getattr() etc... Is this worth pursuing, and has anyone tried it? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Never-saved orphans are an error?
The following code raises a FlushError because the child object named Cheshire is an orphan and the delete-orphan cascade rule is in effect. It seems to me that an orphan which has no database identity should be detached from its session, just as it was attached when appended to a parent's list of children. Why does SA raise an exception instead? from sqlalchemy import * import sys meta = BoundMetaData(sys.argv[1]) parentTable = Table(tether_parents, meta, Column(id, Integer, Sequence(seq_tether_parents), primary_key = True), Column(name, String(10), nullable = False)) childTable = Table(tether_children, meta, Column(id, Integer, Sequence(seq_tether_children), primary_key = True), Column(parent_id, Integer, ForeignKey(tether_parents.id), nullable = False), Column(name, String(10), nullable = False)) class Child(object): def __init__(self, name): self.name = name def __repr__(self): return Child(%s) % repr(self.name) class Parent(object): def __init__(self, name): self.name = name children = [] def __repr__(self): return Parent(%s) % repr(self.name) mapper(Child, childTable) mapper(Parent, parentTable, properties = dict(children = relation(Child,cascade=all,delete-orphan))) meta.drop_all() meta.create_all() meta.engine.echo = False sess = create_session() p = Parent(Carroll) p.children = [Child(Alice), Child(Dee), Child(Dum)] sess.save(p) sess.flush() sess.close() sess = create_session(echo_uow = True) p = sess.query(Parent).get_by_name(Carroll) # New child. p.children.append(Child(Cheshire)) # Oops, changed my mind. del p.children[3] sess.flush() sess.close() --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Never-saved orphans are an error?
Forgot to say I'm using SA 0.3.4. On Feb 9, 5:05 pm, SteveTether [EMAIL PROTECTED] wrote: The following code raises a FlushError because the child object named Cheshire is an orphan and the delete-orphan cascade rule is in effect. It seems to me that an orphan which has no database identity should be detached from its session, just as it was attached when appended to a parent's list of children. Why does SA raise an exception instead? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---