[sqlalchemy] Re: duplicating relation()s
mmh. maybe something around cascades? your 'links' are also not an asociation. On Tuesday 16 December 2008 17:09:49 Julien Cigar wrote: Hi svil, OK, I found back http://groups.google.com/group/sqlalchemy/browse_thread/thread/c1bd 8cfe862441d6/83f3d5d6fde74b89 It seems that the way I planned to do it is the right way to do it if I understood well. I added the lines 113-117 at http://pastebin.com/f17e29b0f but it gives me an error : class 'sqlalchemy.orm.exc.FlushError': Instance SpeciesRegion at 0x8f216cc is an unsaved, pending instance and is an orphan (is not attached to any parent 'Species' instance via that classes' 'regions' attribute) Any idea ? Thanks, Julien On Tue, 2008-12-16 at 16:10 +0200, a...@svilendobrev.com wrote: look down the group recently, there was a similar question on .copy(). this is more of a semantical question, because diff.things need be treated differently. - own references 1:1 - either None or copy of the referenced object - references m:1 - the reference itself - collecions 1:many) - either new empty collection or new collection of copies of the items - asociation - new collection conating links betwen new owner and the items. there may be more sematics involved, e.g. in bitemporal case all above are implemented as associations but are not always treated as such, copy-wise. and other cases. svil On Tuesday 16 December 2008 15:04:03 Julien Cigar wrote: Dear SQLAlchemy users, I have a mapped object called Species with a lot of relation() in it. The user wants to have a duplicate function, so for a given Species a new exact copy should be created, with all the relation(). I have pasted a copy of my code here : http://pastebin.com/f3e50a4fa As you can see at lines 53-55 of my paste, I just iterate on those relations and I use a setattr() on the new object. It works perfectly, except for the regions relation (line 16), where SQLAlchemy does UPDATE statements: it replaces the SpeciesRegion.species_id of the source Species with the new duplicated Species.id, so the source Species has no more regions (SpeciesRegion). It seems logical to me because SpeciesRegion is an association object, but I wondered if there is a better way to do it than 1) iterate of SpeciesRegion objects of the source Species, 2) create a new SpeciesRegion, 3) Adapting SpeciesRegion.region 4) add the new SpeciesRegion to the new Species.regions ? Thanks, Julien --~--~-~--~~~---~--~~ 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: [SA0.5b4/Postgres 7.4] ValueError: 'need more than 0 values to unpack'
your mappers are failing to compile (i.e. if you were to call compile_mappers() manually), and the stack trace is specific to a relation(), which you haven't illustrated in your setup. On Dec 16, 2008, at 7:31 AM, Andreas Jung wrote: Hi, I have a fairly complex model using the declarative layer. For a simple table 'fassung' Toolbox2=# \d fassung Table public.fassung Column| Type | Modifiers -+--- + id | bigint| not null default nextval('fassung_id_key'::text) nr | integer | bezeichnung | character varying(50) | Indexes: fassung_pkey primary key, btree (id) I habe the following definition 178 class Fassung(Base):$ 179 __tablename__ = 'fassung' 180 __table_args__ = ( 181 { 'autoload' : True, } 182 ) A simple query fails badly from within a unittest. I have checked the whole mode definition and could not find and further reference to the 'Fassung' mapper or 'fassung' table. Bug or feature? Andreas --- /local/HRS2/Devel/ajung/tb-dev/parts/modules-svn/toolbox/database/ tests/test_database.py(61)testSimpleSelects() - rows = session.query(mapper).limit(50).all() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/session.py(908)query() - return self._query_cls(entities, self, **kwargs) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/query.py(95)__init__() - self.__setup_aliasizers(self._entities) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/query.py(109)__setup_aliasizers() - mapper, selectable, is_aliased_class = _entity_info(entity) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/util.py(466)_entity_info() - mapper = class_mapper(entity, compile) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/util.py(543)class_mapper() - mapper = mapper.compile() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/mapper.py(679)compile() - mapper._post_configure_properties() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/mapper.py(701)_post_configure_properties() - prop.init(key, self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/interfaces.py(404)init() - self.do_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(579)do_init() - self._post_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(838)_post_init() - self.backref.compile(self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(989)compile() - mapper._compile_property(self.key, relation); /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/mapper.py(643)_compile_property() - prop.init(key, self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/interfaces.py(404)init() - self.do_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(578)do_init() - self._determine_local_remote_pairs() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(814)_determine_local_remote_pairs() - self.local_side, self.remote_side = [util.OrderedSet(x) for x in zip(*list(self.local_remote_pairs))] begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;; 72070;Germany email;internet:i...@zopyx.com title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard --~--~-~--~~~---~--~~ 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: [SA0.5b4/Postgres 7.4] ValueError: 'need more than 0 values to unpack'
There is no relation() involved here. Every relation() related code is commented right now. (see attachment). Andreas On Tue, Dec 16, 2008 at 4:48 PM, Michael Bayer mike...@zzzcomputing.comwrote: your mappers are failing to compile (i.e. if you were to call compile_mappers() manually), and the stack trace is specific to a relation(), which you haven't illustrated in your setup. On Dec 16, 2008, at 7:31 AM, Andreas Jung wrote: Hi, I have a fairly complex model using the declarative layer. For a simple table 'fassung' Toolbox2=# \d fassung Table public.fassung Column| Type | Modifiers -+--- + id | bigint| not null default nextval('fassung_id_key'::text) nr | integer | bezeichnung | character varying(50) | Indexes: fassung_pkey primary key, btree (id) I habe the following definition 178 class Fassung(Base):$ 179 __tablename__ = 'fassung' 180 __table_args__ = ( 181 { 'autoload' : True, } 182 ) A simple query fails badly from within a unittest. I have checked the whole mode definition and could not find and further reference to the 'Fassung' mapper or 'fassung' table. Bug or feature? Andreas --- /local/HRS2/Devel/ajung/tb-dev/parts/modules-svn/toolbox/database/ tests/test_database.py(61)testSimpleSelects() - rows = session.query(mapper).limit(50).all() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/session.py(908)query() - return self._query_cls(entities, self, **kwargs) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/query.py(95)__init__() - self.__setup_aliasizers(self._entities) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/query.py(109)__setup_aliasizers() - mapper, selectable, is_aliased_class = _entity_info(entity) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/util.py(466)_entity_info() - mapper = class_mapper(entity, compile) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/util.py(543)class_mapper() - mapper = mapper.compile() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/mapper.py(679)compile() - mapper._post_configure_properties() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/mapper.py(701)_post_configure_properties() - prop.init(key, self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/interfaces.py(404)init() - self.do_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(579)do_init() - self._post_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(838)_post_init() - self.backref.compile(self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(989)compile() - mapper._compile_property(self.key, relation); /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/mapper.py(643)_compile_property() - prop.init(key, self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/interfaces.py(404)init() - self.do_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(578)do_init() - self._determine_local_remote_pairs() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/ orm/properties.py(814)_determine_local_remote_pairs() - self.local_side, self.remote_side = [util.OrderedSet(x) for x in zip(*list(self.local_remote_pairs))] begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;; 72070;Germany email;internet:i...@zopyx.com email%3binternet%3ai...@zopyx.com title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- ## # HaufeCMS Toolbox # (C) 2004-2008, Haufe Mediengruppe ## The Toolbox2 database based on the declarative layer implementation of SQLAlchemy =
[sqlalchemy] Re: Mapping an array of strings?
Michael Bayer ha scritto: hibernate-style custom types are documented here: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html?highlight=typeengine#custom-types or you can use PickleType. Perfect, many thanks! --~--~-~--~~~---~--~~ 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] duplicating relation()s
Dear SQLAlchemy users, I have a mapped object called Species with a lot of relation() in it. The user wants to have a duplicate function, so for a given Species a new exact copy should be created, with all the relation(). I have pasted a copy of my code here : http://pastebin.com/f3e50a4fa As you can see at lines 53-55 of my paste, I just iterate on those relations and I use a setattr() on the new object. It works perfectly, except for the regions relation (line 16), where SQLAlchemy does UPDATE statements: it replaces the SpeciesRegion.species_id of the source Species with the new duplicated Species.id, so the source Species has no more regions (SpeciesRegion). It seems logical to me because SpeciesRegion is an association object, but I wondered if there is a better way to do it than 1) iterate of SpeciesRegion objects of the source Species, 2) create a new SpeciesRegion, 3) Adapting SpeciesRegion.region 4) add the new SpeciesRegion to the new Species.regions ? Thanks, Julien -- Julien Cigar Belgian Biodiversity Platform http://www.biodiversity.be Université Libre de Bruxelles (ULB) Campus de la Plaine CP 257 Bâtiment NO, Bureau 4 N4 115C (Niveau 4) Boulevard du Triomphe, entrée ULB 2 B-1050 Bruxelles Mail: jci...@ulb.ac.be @biobel: http://biobel.biodiversity.be/person/show/471 Tel : 02 650 57 52 --~--~-~--~~~---~--~~ 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: Abstract base class
an abstract base class isn't going to set up the same fields on all descendants since the mapper()/Table() setup occurs during the creation of the individual class using the non-inherited class dict, and unique instances of each of the Column, etc. elements are required as well. concrete inheritance, as referenced in that post, was not designed to be used as a configurational spacesaver and always requires a mapped selectable for the base, which you don't have here, so it's not appropriate for this use case. So for this you'd need a custom metaclass: class MyMeta(DeclarativeMeta): def __init__(cls, classname, bases, dict_): cls.notes = Column(String) DeclarativeMeta.__init__(cls, classname, bases, dict_) Base = declarative_base(metaclass=MyMeta) On Dec 16, 2008, at 12:36 PM, Joril wrote: Hi everyone! I need to declare a few unrelated classes (from a business perspective) that share some attributes/fields, so I thought I could use an abstract class to group these common attributes (note that just a few classes should have them, not every one) This post http://groups.google.it/group/sqlalchemy/msg/d3de02f609a0bbd9?hl=it suggests to use mixins, but I can't get it to work, SQLA generates the tables without the common fields. I'm testing it with this script: from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String from sqlalchemy import create_engine # --- Tables definition Base = declarative_base() class Abstract(object): notes = Column(String) class Concrete(Base, Abstract): __tablename__ = 'concrete' id = Column(Integer, primary_key=True) # --- # DB creation engine = create_engine('sqlite:///:memory:', echo=True) Base.metadata.create_all(engine) Here's the sql call: CREATE TABLE concrete ( id INTEGER NOT NULL, PRIMARY KEY (id) ) What am I missing? Did I misunderstood how the mixin should be used? (I'm using SQLA 0.5rc4) Many thanks! --~--~-~--~~~---~--~~ 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] [SA0.5b4/Postgres 7.4] ValueError: 'need more than 0 values to unpack'
Hi, I have a fairly complex model using the declarative layer. For a simple table 'fassung' Toolbox2=# \d fassung Table public.fassung Column| Type | Modifiers -+---+ id | bigint| not null default nextval('fassung_id_key'::text) nr | integer | bezeichnung | character varying(50) | Indexes: fassung_pkey primary key, btree (id) I habe the following definition 178 class Fassung(Base):$ 179 __tablename__ = 'fassung' 180 __table_args__ = ( 181 { 'autoload' : True, } 182 ) A simple query fails badly from within a unittest. I have checked the whole mode definition and could not find and further reference to the 'Fassung' mapper or 'fassung' table. Bug or feature? Andreas --- /local/HRS2/Devel/ajung/tb-dev/parts/modules-svn/toolbox/database/tests/test_database.py(61)testSimpleSelects() - rows = session.query(mapper).limit(50).all() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/session.py(908)query() - return self._query_cls(entities, self, **kwargs) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/query.py(95)__init__() - self.__setup_aliasizers(self._entities) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/query.py(109)__setup_aliasizers() - mapper, selectable, is_aliased_class = _entity_info(entity) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/util.py(466)_entity_info() - mapper = class_mapper(entity, compile) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/util.py(543)class_mapper() - mapper = mapper.compile() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/mapper.py(679)compile() - mapper._post_configure_properties() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/mapper.py(701)_post_configure_properties() - prop.init(key, self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/interfaces.py(404)init() - self.do_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py(579)do_init() - self._post_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py(838)_post_init() - self.backref.compile(self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py(989)compile() - mapper._compile_property(self.key, relation); /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/mapper.py(643)_compile_property() - prop.init(key, self) /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/interfaces.py(404)init() - self.do_init() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py(578)do_init() - self._determine_local_remote_pairs() /home/ajung/.buildout/eggs/SQLAlchemy-0.5.0rc4-py2.4.egg/sqlalchemy/orm/properties.py(814)_determine_local_remote_pairs() - self.local_side, self.remote_side = [util.OrderedSet(x) for x in zip(*list(self.local_remote_pairs))] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- begin:vcard fn:Andreas Jung n:Jung;Andreas org:ZOPYX Ltd. Co. KG adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany email;internet:i...@zopyx.com title:CEO tel;work:+49-7071-793376 tel;fax:+49-7071-7936840 tel;home:+49-7071-793257 x-mozilla-html:FALSE url:www.zopyx.com version:2.1 end:vcard
[sqlalchemy] Re: duplicating relation()s
Hi svil, OK, I found back http://groups.google.com/group/sqlalchemy/browse_thread/thread/c1bd8cfe862441d6/83f3d5d6fde74b89 It seems that the way I planned to do it is the right way to do it if I understood well. I added the lines 113-117 at http://pastebin.com/f17e29b0f but it gives me an error : class 'sqlalchemy.orm.exc.FlushError': Instance SpeciesRegion at 0x8f216cc is an unsaved, pending instance and is an orphan (is not attached to any parent 'Species' instance via that classes' 'regions' attribute) Any idea ? Thanks, Julien On Tue, 2008-12-16 at 16:10 +0200, a...@svilendobrev.com wrote: look down the group recently, there was a similar question on .copy(). this is more of a semantical question, because diff.things need be treated differently. - own references 1:1 - either None or copy of the referenced object - references m:1 - the reference itself - collecions 1:many) - either new empty collection or new collection of copies of the items - asociation - new collection conating links betwen new owner and the items. there may be more sematics involved, e.g. in bitemporal case all above are implemented as associations but are not always treated as such, copy-wise. and other cases. svil On Tuesday 16 December 2008 15:04:03 Julien Cigar wrote: Dear SQLAlchemy users, I have a mapped object called Species with a lot of relation() in it. The user wants to have a duplicate function, so for a given Species a new exact copy should be created, with all the relation(). I have pasted a copy of my code here : http://pastebin.com/f3e50a4fa As you can see at lines 53-55 of my paste, I just iterate on those relations and I use a setattr() on the new object. It works perfectly, except for the regions relation (line 16), where SQLAlchemy does UPDATE statements: it replaces the SpeciesRegion.species_id of the source Species with the new duplicated Species.id, so the source Species has no more regions (SpeciesRegion). It seems logical to me because SpeciesRegion is an association object, but I wondered if there is a better way to do it than 1) iterate of SpeciesRegion objects of the source Species, 2) create a new SpeciesRegion, 3) Adapting SpeciesRegion.region 4) add the new SpeciesRegion to the new Species.regions ? Thanks, Julien -- Julien Cigar Belgian Biodiversity Platform http://www.biodiversity.be Université Libre de Bruxelles (ULB) Campus de la Plaine CP 257 Bâtiment NO, Bureau 4 N4 115C (Niveau 4) Boulevard du Triomphe, entrée ULB 2 B-1050 Bruxelles Mail: jci...@ulb.ac.be @biobel: http://biobel.biodiversity.be/person/show/471 Tel : 02 650 57 52 --~--~-~--~~~---~--~~ 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] Vague InterfaceError (threading issue?) running normal query
I'm using CherryPy with SQLAlchemy. I've tried this with both SQLAlchemy's scoped_session thread-local sessions, as well as (also local-to-thread) sessions I create in my web code manually. 2008-12-16 11:51:14,524 DEBUG cherrypy.error.140068141119376: [16/Dec/ 2008:11:51:14] HTTP Traceback (most recent call last): File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 1027, in first ret = list(self[0:1]) File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 952, in __getitem__ return list(res) File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 1088, in __iter__ return self._execute_and_instances(context) File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 1091, in _execute_and_instances result = self.session.execute(querycontext.statement, params=self._params, mapper=self._mapper_zero_or_none(), _state=self._refresh_state) File /usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py, line 749, in execute return self.__connection(engine, close_with_result=True).execute( File /usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py, line 806, in execute return Connection.executors[c](self, object, multiparams, params) File /usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py, line 856, in execute_clauseelement return self.__execute_context(context) File /usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py, line 878, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context) File /usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py, line 927, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor) File /usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py, line 909, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) InterfaceError: (InterfaceError) (0, '') u'SELECT login.username AS login_username, login.password AS login_password, login.`loginId` AS `login_loginId`, login.salt AS login_salt, login.email AS login_email, login.status AS login_status, login.message AS login_message, login.`accountId` AS `login_accountId` \nFROM login \nWHERE login.`loginId` = %s \n LIMIT 0, 1' [36L] The first time this query runs, it works fine. Thereafter I get this error message. Any ideas? --~--~-~--~~~---~--~~ 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] is eager loading unidirectional when using backrefs?
I've ran into this and i'm not sure if this is a bug or a feature, but I haven't read anything about this. I had: two tables: groups and group_types, where groups had an fk to group_types groups: id, name, group_type_id group_types: id, name two mappers: group_mapper: lazy=False group_types_mapper: this defined 'group_type' as a backref'd attribute of group, lazy=False what I've noticed is that, eager loading of group_type did NOT work when loading a group, in this case, when I would've expected it to. however, after I moved the definition of the group_type attribute to the groups mapper (out of group_types_mapper), eager loading worked just fine. Is this a known bug or feature? thanks for any feedback. --~--~-~--~~~---~--~~ 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: is eager loading unidirectional when using backrefs?
On Dec 16, 2008, at 1:58 PM, tobin wrote: I've ran into this and i'm not sure if this is a bug or a feature, but I haven't read anything about this. I had: two tables: groups and group_types, where groups had an fk to group_types groups: id, name, group_type_id group_types: id, name two mappers: group_mapper: lazy=False group_types_mapper: this defined 'group_type' as a backref'd attribute of group, lazy=False what I've noticed is that, eager loading of group_type did NOT work when loading a group, in this case, when I would've expected it to. however, after I moved the definition of the group_type attribute to the groups mapper (out of group_types_mapper), eager loading worked just fine. Is this a known bug or feature? if the question is, does backref() accept lazy=False, the answer is yes. a backref() is just configuration-ese for relation(), with some extra flags present. I dont know why you didn't observe eager loading to take place in your specific instance, you'd have to post a small program that illustrates and can reproduce how you got the behavior you're seeing. --~--~-~--~~~---~--~~ 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] Polymorphic Identity and declarative base
A newbie question: Is there a way to define a subclass using declarative base which defined the polymorphic identity on more than one value? Is there a way to do it outside the declarative base? A bane example: In subclass Citrus I would like to be able to declare several types of fruits class Fruits(Base) __mapper_args__ = {'polymorphic_on': type} class Citrus(Fruits) __mapper_args__ = {'polymorphic_identity': 'orange'} __mapper_args__ = {'polymorphic_identity': 'lemon'} But this doesn't work ... but I would like subclass Citrus to relate to both ORANGE and LEMON Thanks --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---