[sqlalchemy] Re: XX and YY are both of the same direction symbol 'ONETOMANY error
I have exactly the same problem with 0.5.3. On one machine the mapping works fine with 0.5.2 on another with 0.5.3 I get the error you mentioned. On Apr 2, 3:36 pm, Andreas Jung li...@zopyx.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I am getting the following error after upgrading from post-0.5.2 version (SVN) to 0.5.3: == ERROR: testToolLookupVisitedBy (tool.tests.test_tool_lookup.TestToolLookup) - -- Traceback (most recent call last): File /HRS2/local/lib/python2.4/unittest.py, line 260, in run testMethod() File /local/HRS2/Devel/junga/tb-dev/parts/modules-svn/toolbox/tool/tests/test_tool_lookup.py, line 47, in testToolLookupVisitedBy rows = TL.toolsVisitedBy('ajung') File /local/HRS2/Devel/junga/tb-dev/parts/modules-svn/toolbox/tool/__init__.py, line 70, in toolsVisitedBy visited_tools = session.query(VT).filter_by(benutzer=username.lower()) File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/session.py, line 895, in query return self._query_cls(entities, self, **kwargs) File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/query.py, line 91, in __init__ self._set_entities(entities) File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/query.py, line 100, in _set_entities self.__setup_aliasizers(self._entities) File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/query.py, line 114, in __setup_aliasizers mapper, selectable, is_aliased_class = _entity_info(entity) File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/util.py, line 492, in _entity_info mapper = class_mapper(entity, compile) File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/util.py, line 567, in class_mapper mapper = mapper.compile() File /local/HRS2/Devel/junga/tb-dev/eggs/SQLAlchemy-0.5.3-py2.4.egg/sqlalchemy/orm/mapper.py, line 653, in compile raise sa_exc.InvalidRequestError(One or more mappers failed to compile. Exception was probably InvalidRequestError: One or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: One or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: One or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: One or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: Hierarchies.subscribed_by and back-reference Hierarchies.subscriber are both of the same direction symbol 'ONETOMANY. Did you mean to set remote_side on the many-to-one side ? The related code is: class Hierarchies(Base, AsDictMixin): __tablename__ = 'hierarchies' __table_args__ = ( { 'autoload' : True, }) __mapper_args__ = ({'extension' : HierachiesDeletionLogger()}) id = Column(Integer, Sequence('hierarchies_seq'), primary_key=True) parent_id = Column(Integer, ForeignKey('hierarchies.id')) hierarchyshare_id = Column(Integer, ForeignKey('hierarchies.id')) pos = Column(Integer) Hierarchies.subscribed_by = relation('Hierarchies', primaryjoin=Hierarchies.hierarchyshare_id==Hierarchies.id, backref=backref(subscriber, remote_side=Hierarchies.hierarchyshare_id), remote_side=Hierarchies.hierarchyshare_id, uselist=True, ) Anything I am missing or something that changed over the last two weeks at this point? Andreas - -- ZOPYX Ltd. Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web:www.zopyx.com- Email: i...@zopyx.com - Phone +49 - 7071 - 793376 Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535 Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK - E-Publishing, Python, Zope Plone development, Consulting -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (Darwin) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ iEYEARECAAYFAknUzXIACgkQCJIWIbr9KYwdZgCfVfo9ZN2bNPM4iaxZoFXdcuuE yPoAoMaqN2Wr219oL+kviY7dtotIqh/M =RG8E -END PGP SIGNATURE- lists.vcf 1KViewDownload --~--~-~--~~~---~--~~ 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
[sqlalchemy] Re: When to create new sessions?
On Thursday 09 April 2009 05:14:36 Bobby Impollonia wrote: Now the decorator swallows exceptions silently. You have to reraise the exception after rolling back like Michael did. I believe the correct form is: Darn.. you're right of course :) Diez --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: 0.5.3 and mssql
This is what's working for me with 0.5.3 raw_cs = SERVER=%s;DATABASE=%s;UID=%s;PWD=%s % (server, database, userid, password) connection_string = %s:///?odbc_connect=%s % (databasetype, urllib.quote_plus(raw_cs)) if databasetype in ['mssql']: connection_string += urllib.quote_plus(;DRIVER={SQL Server};TDS_Version=8.0) echoOn = True # For debugging the SQL statements engine = create_engine(connection_string, echo=echoOn) If TDSVER is not seen and the default version is used, you may get SystemError: 'finally' pops bad exception Now that said I have also had to force the version with ./configure --with-tdsver=8.0 make sudo make install or export TDSVER=8.0 or if you can't redeploy freetds copy freetds.conf to ~/.freetds.conf and change the version in that file to 8.0 FreeTS, ODBC, pyODBC and then SQLAlchemy: what a house of cards! ~Matt On Apr 7, 12:58 pm, Lukasz Szybalski szybal...@gmail.com wrote: Hello, Is this still proper connection string for mssql where I specify the tds version and a connection driver name? e = sqlalchemy.create_engine(mssql://user:p...@server:1433/db_name?driver=TDSodbc_options='TDS_Version=8.0') What is the syntax for driver, and how can I pass TDS_Version=8.0 to the end of connection string? Thanks, Lucas File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py, line 198, in __init__ self.connection = self.__connect() File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py, line 261, in __connect connection = self.__pool._creator() File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/strategies.py, line 80, in connect raise exc.DBAPIError.instance(None, None, e) sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnectW)') None None -- How to create python package?http://lucasmanual.com/mywiki/PythonPaste DataHub - create a package that gets, parses, loads, visualizes datahttp://lucasmanual.com/mywiki/DataHub --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: relation that works in .48 but fails in .53
Bobby Impollonia wrote: Is there a video or slides from that pycon talk available online? I see the overview on the pycon site (http://us.pycon.org/2009/tutorials/schedule/2PM4/) and it looks very interesting. I looked more at what you said about the parent id column taking precedence and that does seem to be what happens. In particular, I see that the sql generated for session.query(Child1).filter( Child1.id.in_( range(5))) .count() uses the IN condition on parent.id in .53, whereas it was on the child1.id in .48. The .48 behavior seems better here. I can't think of a situation where I would say Child1.id and want it to use the column from the parent table instead of the child. Regardless, now that I understand what is happening, I will be able to get my application working on .53. I dont recall the exact use cases that still require this. the gist is if you said : session.query(Child.id, Child.name) you'd probably want select id, name from parent instead of select child.id, parent.name from parent join child on that's not exactly the case where it comes into play, but its along those lines. Child.id really represents the id column of your joined table, which is most prominently parent.id. Child is not the same as the child table.I can try changing the order of columns and see what the unit tests say these days. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: XX and YY are both of the same direction symbol 'ONETOMANY error
On Apr 2, 10:36 am, Andreas Jung li...@zopyx.com wrote: The related code is: class Hierarchies(Base, AsDictMixin): __tablename__ = 'hierarchies' __table_args__ = ( { 'autoload' : True, }) __mapper_args__ = ({'extension' : HierachiesDeletionLogger()}) id = Column(Integer, Sequence('hierarchies_seq'), primary_key=True) parent_id = Column(Integer, ForeignKey('hierarchies.id')) hierarchyshare_id = Column(Integer, ForeignKey('hierarchies.id')) pos = Column(Integer) Hierarchies.subscribed_by = relation('Hierarchies', primaryjoin=Hierarchies.hierarchyshare_id==Hierarchies.id, backref=backref(subscriber, remote_side=Hierarchies.hierarchyshare_id), remote_side=Hierarchies.hierarchyshare_id, uselist=True, ) yes, you have the same remote_side on both the forwards and the backwards reference, indicating they are both one-to-many from hierarchies.id to hiearchies.parent_id. The remote_side in the many- to-one backref should point to Hierarchies.id. Anything I am missing or something that changed over the last two weeks at this point? Andreas - -- ZOPYX Ltd. Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web:www.zopyx.com- Email: i...@zopyx.com - Phone +49 - 7071 - 793376 Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535 Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK - E-Publishing, Python, Zope Plone development, Consulting -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (Darwin) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ iEYEARECAAYFAknUzXIACgkQCJIWIbr9KYwdZgCfVfo9ZN2bNPM4iaxZoFXdcuuE yPoAoMaqN2Wr219oL+kviY7dtotIqh/M =RG8E -END PGP SIGNATURE- lists.vcf 1KViewDownload --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: 0.5.3 and mssql
On Wed, Apr 8, 2009 at 11:36 PM, mdoar md...@pobox.com wrote: This is what's working for me with 0.5.3 raw_cs = SERVER=%s;DATABASE=%s;UID=%s;PWD=%s % (server, database, userid, password) connection_string = %s:///?odbc_connect=%s % (databasetype, urllib.quote_plus(raw_cs)) if databasetype in ['mssql']: connection_string += urllib.quote_plus(;DRIVER={SQL Server};TDS_Version=8.0) echoOn = True # For debugging the SQL statements engine = create_engine(connection_string, echo=echoOn) What version of pyodbc are you using? Thanks, Lucas If TDSVER is not seen and the default version is used, you may get SystemError: 'finally' pops bad exception Now that said I have also had to force the version with ./configure --with-tdsver=8.0 make sudo make install or export TDSVER=8.0 or if you can't redeploy freetds copy freetds.conf to ~/.freetds.conf and change the version in that file to 8.0 FreeTS, ODBC, pyODBC and then SQLAlchemy: what a house of cards! ~Matt On Apr 7, 12:58 pm, Lukasz Szybalski szybal...@gmail.com wrote: Hello, Is this still proper connection string for mssql where I specify the tds version and a connection driver name? e = sqlalchemy.create_engine(mssql://user:p...@server:1433/db_name?driver=TDSodbc_options='TDS_Version=8.0') What is the syntax for driver, and how can I pass TDS_Version=8.0 to the end of connection string? Thanks, Lucas File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py, line 198, in __init__ self.connection = self.__connect() File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py, line 261, in __connect connection = self.__pool._creator() File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/strategies.py, line 80, in connect raise exc.DBAPIError.instance(None, None, e) sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnectW)') None None -- How to create python package?http://lucasmanual.com/mywiki/PythonPaste DataHub - create a package that gets, parses, loads, visualizes datahttp://lucasmanual.com/mywiki/DataHub -- How to create python package? http://lucasmanual.com/mywiki/PythonPaste DataHub - create a package that gets, parses, loads, visualizes data http://lucasmanual.com/mywiki/DataHub --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: 0.5.3 and mssql
On Apr 9, 8:20 am, Lukasz Szybalski szybal...@gmail.com wrote: On Wed, Apr 8, 2009 at 11:36 PM, mdoar md...@pobox.com wrote: This is what's working for me with 0.5.3 raw_cs = SERVER=%s;DATABASE=%s;UID=%s;PWD=%s % (server, database, userid, password) connection_string = %s:///?odbc_connect=%s % (databasetype, urllib.quote_plus(raw_cs)) if databasetype in ['mssql']: connection_string += urllib.quote_plus(;DRIVER={SQL Server};TDS_Version=8.0) echoOn = True # For debugging the SQL statements engine = create_engine(connection_string, echo=echoOn) What version of pyodbc are you using? Latest and greatest stable ~Matt Thanks, Lucas If TDSVER is not seen and the default version is used, you may get SystemError: 'finally' pops bad exception Now that said I have also had to force the version with ./configure --with-tdsver=8.0 make sudo make install or export TDSVER=8.0 or if you can't redeploy freetds copy freetds.conf to ~/.freetds.conf and change the version in that file to 8.0 FreeTS, ODBC, pyODBC and then SQLAlchemy: what a house of cards! ~Matt On Apr 7, 12:58 pm, Lukasz Szybalski szybal...@gmail.com wrote: Hello, Is this still proper connection string for mssql where I specify the tds version and a connection driver name? e = sqlalchemy.create_engine(mssql://user:p...@server:1433/db_name?driver=TDSodbc_options='TDS_Version=8.0') What is the syntax for driver, and how can I pass TDS_Version=8.0 to the end of connection string? Thanks, Lucas File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py, line 198, in __init__ self.connection = self.__connect() File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/pool.py, line 261, in __connect connection = self.__pool._creator() File /home/lucas/tmp/saENV/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/engine/strategies.py, line 80, in connect raise exc.DBAPIError.instance(None, None, e) sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnectW)') None None -- How to create python package?http://lucasmanual.com/mywiki/PythonPaste DataHub - create a package that gets, parses, loads, visualizes datahttp://lucasmanual.com/mywiki/DataHub -- How to create python package?http://lucasmanual.com/mywiki/PythonPaste DataHub - create a package that gets, parses, loads, visualizes datahttp://lucasmanual.com/mywiki/DataHub --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Readonly performance
I'm using declarative classes for a table with a few foreign keys to other tables. When I look at the SQL queries I see the query to get all the rows of the main table and then a few extra queries for each row's foreign keys; all as expected. However, it seems that since I am not modifying any of the tables, there might be a way to have the secondary tables loaded once to avoid the multiple queries per row that is killing performance right now. Am I missing some option that already exists? ~Matt --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Readonly performance
mdoar wrote: I'm using declarative classes for a table with a few foreign keys to other tables. When I look at the SQL queries I see the query to get all the rows of the main table and then a few extra queries for each row's foreign keys; all as expected. However, it seems that since I am not modifying any of the tables, there might be a way to have the secondary tables loaded once to avoid the multiple queries per row that is killing performance right now. Am I missing some option that already exists? the many-to-one loads will place those entities in the session keyed to their primary key. when a lazyloader on a parent object fires off, it checks the identity map first before loading.So as long as that object was already loaded and is strongly referenced, it wont use SQL. Here's what is needed for that to work. 1. strongly referenced somewhere, or weak_identity_map=False on your session. else the object is garbage collected and SQL is required to load it. 2. the relation is many-to-one and would use the same SQL to load as that of a query.get(). For simple many-to-ones this always the case, but in the case of custom primaryjoin conditions or with some inheritance scenarios, its not. If your many-to-one references a column on a joined-table inheriting class, specify a custom primaryjoin that references the primary key column(s) on the base table - you'll need the foreign_keys argument for this too. ~Matt --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Readonly performance
On Apr 9, 12:19 pm, Michael Bayer mike...@zzzcomputing.com wrote: mdoar wrote: I'm using declarative classes for a table with a few foreign keys to other tables. When I look at the SQL queries I see the query to get all the rows of the main table and then a few extra queries for each row's foreign keys; all as expected. However, it seems that since I am not modifying any of the tables, there might be a way to have the secondary tables loaded once to avoid the multiple queries per row that is killing performance right now. Am I missing some option that already exists? the many-to-one loads will place those entities in the session keyed to their primary key. when a lazyloader on a parent object fires off, it checks the identity map first before loading. So as long as that object was already loaded and is strongly referenced, it wont use SQL. Makes sense. Since I'm using reflection and declarative, I have code like aTable = Table(tablename, Base.metadata, Column('dbid', primary_key=True), Column('state', index=True), useexisting=True) clz = type(classname, (Base,), {'__table__' : aTable}) and then define a relation later on with: Defect.stateObj = orm.relation(Statedef, primaryjoin=Defect.state==Statedef.id, foreign_keys= [Statedef.__table__.columns['id'] ]) Here's what is needed for that to work. 1. strongly referenced somewhere, or weak_identity_map=False on your session. else the object is garbage collected and SQL is required to load it. weak_identity_map=False is the default. Looking at the documentation, perhaps you meant weak_identity_map=True? 2. the relation is many-to-one and would use the same SQL to load as that of a query.get(). For simple many-to-ones this always the case, but in the case of custom primaryjoin conditions or with some inheritance scenarios, its not. If your many-to-one references a column on a joined-table inheriting class, specify a custom primaryjoin that references the primary key column(s) on the base table - you'll need the foreign_keys argument for this too. I have an explicit primaryjoin as shown above but it sounds like this should still hold? ~Matt --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: relation that works in .48 but fails in .53
Bobby Impollonia wrote: Is there a video or slides from that pycon talk available online? I see the overview on the pycon site (http://us.pycon.org/2009/tutorials/schedule/2PM4/) and it looks very interesting. we haven't put anything on line as of yet. I also just remembered that the section where I talked about the foo_id issue was probably not in the final slides we used. I looked more at what you said about the parent id column taking precedence and that does seem to be what happens. In particular, I see that the sql generated for session.query(Child1).filter( Child1.id.in_( range(5))) .count() uses the IN condition on parent.id in .53, whereas it was on the child1.id in .48. The .48 behavior seems better here. I can't think of a situation where I would say Child1.id and want it to use the column from the parent table instead of the child. I ran the tests with the order reversed and not too much failed. but here's one of the surprises you'll get: p = session.query(Parent).filter(...some criteiron...).one() suppose you get a Child1 object from the above. Then say: print p.id id is now child1.id. the above load will *force a load of the child table*, even though parent.id is right there. If the guts of column attributes were really overhauled to adjust for every scenario, meaning Child.id gives you child1.id, but the instance somechild.id knows to give you the value bound to parent.id, I suppose it may be possible for there to be no surprises. but at the core of it, the mapper maps columns to your class. if you're mapping a single class to two tables, the docs/mapper should make it apparent that the attribute is shared between two columns and if you want direct access to both, you should split them up. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Readonly performance
mdoar wrote: Makes sense. Since I'm using reflection and declarative, I have code like aTable = Table(tablename, Base.metadata, Column('dbid', primary_key=True), Column('state', index=True), useexisting=True) clz = type(classname, (Base,), {'__table__' : aTable}) and then define a relation later on with: Defect.stateObj = orm.relation(Statedef, primaryjoin=Defect.state==Statedef.id, foreign_keys= [Statedef.__table__.columns['id'] ]) i think you mean to say here that foreign_keys=Defect.state. if the foreign keys are on the other side, thats one to many. 1. strongly referenced somewhere, or weak_identity_map=False on your session. else the object is garbage collected and SQL is required to load it. weak_identity_map=False is the default. Looking at the documentation, perhaps you meant weak_identity_map=True? True is the default in 4 and above and it seems like the docstring has it backwards, so that is fixed in r5903. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] PostgreSQL executemany and result.last_inserted_ids()
I'm trying to use SQLAlchemy's executemany syntax in PostgreSQL and get the last_inserted_ids(). What is the recommended way to get these last_inserted_ids()? I know that I can access the id attribute for each model instance but there are hundreds of inserted rows and I would rather retrieve them all at once. Thanks, RHH names = ['ted', 'steve', 'mike'] result = meta.Session.execute(model.names_table.insert(), [{'name': x} for x in names]) result.last_inserted_ids() Traceback (most recent call last): File /usr/lib/python2.5/site-packages/WebError-0.10.1-py2.5.egg/weberror/evalcontext.py, line 35, in exec_expr exec code in self.namespace, self.globs File web, line 1, in module File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/engine/base.py, line 1560, in last_inserted_ids return self.context.last_inserted_ids() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/engine/default.py, line 284, in last_inserted_ids return self._last_inserted_ids AttributeError: 'PGExecutionContext' object has no attribute '_last_inserted_ids' --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: PostgreSQL executemany and result.last_inserted_ids()
Yay! I solved it. Thanks for making such a great module. result = meta.Session.execute(model.names_table.insert(postgres_returning=[model.names_table.c.id]), [{'name': x} for x in names]) result.fetchall() [(40,), (41,), (42,)] On Thu, Apr 9, 2009 at 6:05 PM, Roy Hyunjin Han starsareblueandfara...@gmail.com wrote: I'm trying to use SQLAlchemy's executemany syntax in PostgreSQL and get the last_inserted_ids(). What is the recommended way to get these last_inserted_ids()? I know that I can access the id attribute for each model instance but there are hundreds of inserted rows and I would rather retrieve them all at once. Thanks, RHH names = ['ted', 'steve', 'mike'] result = meta.Session.execute(model.names_table.insert(), [{'name': x} for x in names]) result.last_inserted_ids() Traceback (most recent call last): File /usr/lib/python2.5/site-packages/WebError-0.10.1-py2.5.egg/weberror/evalcontext.py, line 35, in exec_expr exec code in self.namespace, self.globs File web, line 1, in module File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/engine/base.py, line 1560, in last_inserted_ids return self.context.last_inserted_ids() File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/engine/default.py, line 284, in last_inserted_ids return self._last_inserted_ids AttributeError: 'PGExecutionContext' object has no attribute '_last_inserted_ids' --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Readonly performance
On Apr 9, 2:48 pm, Michael Bayer mike...@zzzcomputing.com wrote: mdoar wrote: Makes sense. Since I'm using reflection and declarative, I have code like aTable = Table(tablename, Base.metadata, Column('dbid', primary_key=True), Column('state', index=True), useexisting=True) clz = type(classname, (Base,), {'__table__' : aTable}) and then define a relation later on with: Defect.stateObj = orm.relation(Statedef, primaryjoin=Defect.state==Statedef.id, foreign_keys= [Statedef.__table__.columns['id'] ]) i think you mean to say here that foreign_keys=Defect.state. if the foreign keys are on the other side, thats one to many. I do indeed have it set up as one to many and then I get the first instance. Does that change the solution? 1. strongly referenced somewhere, or weak_identity_map=False on your session. else the object is garbage collected and SQL is required to load it. weak_identity_map=False is the default. Looking at the documentation, perhaps you meant weak_identity_map=True? True is the default in 4 and above and it seems like the docstring has it backwards, so that is fixed in r5903. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: PostgreSQL executemany and result.last_inserted_ids()
Roy Hyunjin Han wrote: I'm trying to use SQLAlchemy's executemany syntax in PostgreSQL and get the last_inserted_ids(). What is the recommended way to get these last_inserted_ids()? I know that I can access the id attribute for each model instance but there are hundreds of inserted rows and I would rather retrieve them all at once. this is not available for executemany. its a limitation of DBAPI. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: XX and YY are both of the same direction symbol 'ONETOMANY error
Adrian wrote: in my case it must be something different. The following code works perfectly fine in 0.5.2: mapper(Contact, CONTACTS) mapper(Atom, ATOMS, properties = { 'Contacts': relation(Contact, primaryjoin = Contact.atom_id==ATOMS.c.id, foreign_keys = [Contact.atom_id], lazy=True, uselist=True, viewonly=True, backref = backref('Atom', primaryjoin = Contact.atom_id==ATOMS.c.id, foreign_keys = [ATOMS.c.id], lazy=True, uselist=False, viewonly=True) ) }) In: atom = session.query(Atom).filter(Atom.id==57).one() In: atom.Contacts Out: [Contact(57, 9)] In 0.5.3 however, the backref() will throw the following error: ArgumentError: Atom.Contacts and back-reference Contact.Atom are both of the same direction symbol 'ONETOMANY. Did you mean to set remote_side on the many-to-one side ? Any ideas? in this case you have set the foreign_keys collection backwards on the backref. the foreign key is always contact.atom_id. its also not needed if you have ForeignKey objects on your table metadata. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: PostgreSQL executemany and result.last_inserted_ids()
Roy Hyunjin Han wrote: Yay! I solved it. Thanks for making such a great module. result = meta.Session.execute(model.names_table.insert(postgres_returning=[model.names_table.c.id]), [{'name': x} for x in names]) result.fetchall() [(40,), (41,), (42,)] this is not going to work consistently on different versions of psycopg2 as they will tell you its not (and will never be) supported. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Readonly performance
mdoar wrote: i think you mean to say here that foreign_keys=Defect.state. if the foreign keys are on the other side, thats one to many. I do indeed have it set up as one to many and then I get the first instance. Does that change the solution? in that case SQLA doesn't have what it needs to load the existing instance without SQL. it must locate the remote instance by finding rows that reference the local id and the session does not cache items by foreign key. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---