[sqlalchemy] Re: M2M relationship
Hi Michael, what I see immediately is that you're declaring mutliple declarative_bases and multiple MetaData objects. All of the Table objects which relate to one another need to share the same underlying MetaData object, and the declarative_base() function also uses a MetaData object which it creates for you, unless one is passed. So you need a global module everyone works from which starts with something like: Thank you for pointing this out, it certainly sounds like it could be the problem, it would explain why none of the tables seem to know about one another :-D I have a singleton module which is a factory for my database connections which gets passed around into the beans, I will place these metadata and declarative base classes into that and see how that helps. I'll give this a try in the next few hours and let you know how I get on. Heston --~--~-~--~~~---~--~~ 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: tree/graph persistency, concurency-safe?
On Monday 14 July 2008 04:05:43 Michael Bayer wrote: On Jul 13, 2008, at 1:47 PM, [EMAIL PROTECTED] wrote: hi all i have a tree/graph of nodes and links inbetween (= explicit m2m), and many users can simultaneusly change nodes/links. i need to get all-reachable-from-x in one query - so i'm saving also all the paths (not just the immediate neibourghs). i think this was called nested-sets or whatever. The question is, (how) can i do that concurency-safe. is version_id a viable/usable solution (can it happen that some poor guy is never able to save his stuff as others always overtake him)? nested sets is awful for concurrency since any node additions or deletions require a full UPDATE of at least half the table's rows. But when you say saving all the paths that sounds more like materialized path. Which I haven't used in a super long time but also would require many large UPDATEs if the tree structure is changing. Depending on what kind of performance you need you can maybe lock the whole table, or queue all the updates/deletes into a single thread/ process..otherwise you might want to look into decreasing the amount of interdependent rows if you want to use version_id or row locking. These are just guesses though without much deep thought put into it. hmm this doesnt sound very hopeful.. i dont really need huge performance as it would be just users (say 20-30 max) touching those. i'm trying different ways to solve my riddle, so here further explanations, and some thinking aloud. i dont really need the tree itself, but the values associated with each node, via another m2m. and these are bitemporal. There is no real update and deletion, they become insertions of new versions - of the associations and (nodes and/or values). There is an inheritance between the node-values, children inherit parent's value if not having own. So i can/want to flatten the _resulting_ set of values for each node (not just it's own but also those that have come from the parent etc till the root), to be able to get all values associate with particular node, as one query. So any change to the tree or to the values of some intermediate node will result into (massive or not) insertions of new associations, flattening the result-set for each child node. e.g. A,B,C are nodes, B,C inherit A A: x=1,y=2; B: x=5,z=6; C: y=7,z=8 flattening results in A: x=1,y=2; B: x=5,y=2,z=6; C: x=1,y=7,z=8 let user1 change A.x to be 9. this results in flattened sets as A: x=9,y=2; B: x=5,y=2,z=6; C: x=9,y=7,z=8 (new values in A.x and C.x, =9) while doing this, another user2 changes it to x=0, and y=3: A: x=0,y=3; B: x=5,y=3,z=6; C: x=0,y=7,z=8 (new values in A.x= C.x=0, A.y= B.y=3) transaction-wise i can ensure (via revision-id instead of trans-timestamp) that the two set of inserts dont mix, so one will either get the first set or the second set but not some cross inbetween. So it's a sort of last-started wins. Still some change by user1 may protrude through, if not covered by user2 changes - and i'm not sure is this wrong or right. maybe it's ok, maybe not; depends if the changes within one set are independent or not (say user1 changes the first name and the family name, user2 changes second name and family name. if that's fixing typos, ok; if its complete change, not ok). . probably such thing cannot be assured at all, or the system has to be single-user. i dont know how if i can or whether i need to do version_id-like checking here - seems like asking if last version is still the one we started with. But between that query and the following Insert someone may stick another value... the inserts has to be conditional and fail if the last-value is not what was supposed to be... which seems awfuly entangled. on rereading above 2 paragraphs, this is called merging in svn-terms. Maybe even this can be assured if the revision-set includes old unchanged values too as-they-were. hmmm. In this case though, user1 will never see his changes, as user2 did his later. maybe rise a conflict, again as in svn terms? now, changes in the tree-structure (not just values) will definitely has to be serialized somehow, but i hope these will be rare enough. svn-parallel of these is moving files/directories and svn isn't very good at it... but bzr is. maybe i should look how they do it.. any comments? svilen --~--~-~--~~~---~--~~ 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: Little Bug - orm.object_mapper.get_property
I refer to the docstring and this is my version: SQLAlchemy-0.5.0beta1- py2.5.egg On Jul 14, 1:59 am, Michael Bayer [EMAIL PROTECTED] wrote: On Jul 13, 2008, at 1:38 PM, Kless wrote: *orm.object_mapper* has an argument called 'raiseerror', and it works ok. *orm.object_mapper.get_property* also has an argument called 'raiseerror' (that says on documentation), but it fails: *unexpected keyword argument 'raiseerror'*. It's using as argument: 'raiseerr'. I dont like those raiseerror flags very much and in reality I'd like to take them out. Although I am not seeing the get_property() documentation you're referring to, in both 0.4 and 0.5 the docstring does not describe the arguments for that method. --~--~-~--~~~---~--~~ 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] Problem: TypeError: Incompatible collection type
Hello! First, sorry about my english! I'm having this little problem, and i can't see where is my error. I have the follow code: code from sqlalchemy import * from sqlalchemy.orm import * class Cuenta(object): def __init__(self, codigo, de_titulo, descripcion, padre): self.codigo = codigo self.de_titulo = de_titulo self.descripcion = descripcion self.padre = padre _metadata = MetaData() cuentas_tabla = Table('cuentas', _metadata, Column('id', Integer, primary_key=True), Column('codigo', String(30), unique=True, nullable=False), Column('de_titulo', Boolean, nullable=False), Column('descripcion', String(150), unique=True, nullable=False), Column('cuenta_padre', Integer, ForeignKey('cuentas.id'), nullable=True) ) mapper(Cuenta, cuentas_tabla, properties={'padre':relation(Cuenta, backref='hijas')}) engine = create_engine('sqlite:///database.txt') Session = sessionmaker(bind=engine, autoflush=True, transactional=False) _metadata.create_all(bind=engine) session = Session() session.begin() activo = Cuenta(codigo='1', de_titulo=True, descripcion='Activo', padre=None) fachadaPersistencia.save(activo) caja = Cuenta(codigo='1.1', de_titulo = False, descripcion='Caja', padre=activo) fachadaPersistencia.save(caja) banco = Cuenta(codigo='1.2', de_titulo = False, descripcion='Banco', padre=activo) fachadaPersistencia.save(banco) pasivo = Cuenta(codigo='2', de_titulo=True, descripcion='Pasivo', padre=None) session.save(pasivo) session.commit() /code And i have the next exception: code Traceback (most recent call last): File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 30, in ? padre=None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 1126, in init oldinit(instance, *args, **kwargs) File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 9, in __init__ self.padre = padre File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 36, in __set__ self.impl.set(instance._state, value, None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 532, in set new_values = list(new_collection.adapt_like_to_iterable(value)) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/collections.py, line 509, in adapt_like_to_iterable raise TypeError( TypeError: Incompatible collection type: NoneType is not list-like /code If I quit the backref, i'm still having that error. If anybody can help me, i will appreciate that. Thanks, Marcos Alcazar Mendoza, Argentina --~--~-~--~~~---~--~~ 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: Problem: TypeError: Incompatible collection type
AFAIRemember, by default, relation assumes it is a collection, and not a reference - as it is in your case (padre means parent, right?) give relation( ... use_list=False). On Monday 14 July 2008 15:21:48 Marcos wrote: Hello! First, sorry about my english! I'm having this little problem, and i can't see where is my error. I have the follow code: code from sqlalchemy import * from sqlalchemy.orm import * class Cuenta(object): def __init__(self, codigo, de_titulo, descripcion, padre): self.codigo = codigo self.de_titulo = de_titulo self.descripcion = descripcion self.padre = padre _metadata = MetaData() cuentas_tabla = Table('cuentas', _metadata, Column('id', Integer, primary_key=True), Column('codigo', String(30), unique=True, nullable=False), Column('de_titulo', Boolean, nullable=False), Column('descripcion', String(150), unique=True, nullable=False), Column('cuenta_padre', Integer, ForeignKey('cuentas.id'), nullable=True) ) mapper(Cuenta, cuentas_tabla, properties={'padre':relation(Cuenta, backref='hijas')}) engine = create_engine('sqlite:///database.txt') Session = sessionmaker(bind=engine, autoflush=True, transactional=False) _metadata.create_all(bind=engine) session = Session() session.begin() activo = Cuenta(codigo='1', de_titulo=True, descripcion='Activo', padre=None) fachadaPersistencia.save(activo) caja = Cuenta(codigo='1.1', de_titulo = False, descripcion='Caja', padre=activo) fachadaPersistencia.save(caja) banco = Cuenta(codigo='1.2', de_titulo = False, descripcion='Banco', padre=activo) fachadaPersistencia.save(banco) pasivo = Cuenta(codigo='2', de_titulo=True, descripcion='Pasivo', padre=None) session.save(pasivo) session.commit() /code And i have the next exception: code Traceback (most recent call last): File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 30, in ? padre=None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 1126, in init oldinit(instance, *args, **kwargs) File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 9, in __init__ self.padre = padre File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 36, in __set__ self.impl.set(instance._state, value, None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 532, in set new_values = list(new_collection.adapt_like_to_iterable(value)) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/collections.py, line 509, in adapt_like_to_iterable raise TypeError( TypeError: Incompatible collection type: NoneType is not list-like /code If I quit the backref, i'm still having that error. If anybody can help me, i will appreciate that. Thanks, Marcos Alcazar Mendoza, Argentina --~--~-~--~~~---~--~~ 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: Problem: TypeError: Incompatible collection type
a reference - as it is in your case (padre means parent, right?) Yes, padre means parent give relation( ... use_list=False). Mmmm... no: code Traceback (most recent call last): File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 20, in ? mapper(Cuenta, cuentas_tabla, properties={'padre':relation(Cuenta,use_list=False)}) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/__init__.py, line 269, in relation return PropertyLoader(argument, secondary=secondary, **kwargs) TypeError: __init__() got an unexpected keyword argument 'use_list' /code I did it right? or I made a mistake? Thanks for your reply, Marcos On 14 jul, 10:11, [EMAIL PROTECTED] wrote: AFAIRemember, by default, relation assumes it is a collection, and not a reference - as it is in your case (padre means parent, right?) give relation( ... use_list=False). On Monday 14 July 2008 15:21:48 Marcos wrote: Hello! First, sorry about my english! I'm having this little problem, and i can't see where is my error. I have the follow code: code from sqlalchemy import * from sqlalchemy.orm import * class Cuenta(object): def __init__(self, codigo, de_titulo, descripcion, padre): self.codigo = codigo self.de_titulo = de_titulo self.descripcion = descripcion self.padre = padre _metadata = MetaData() cuentas_tabla = Table('cuentas', _metadata, Column('id', Integer, primary_key=True), Column('codigo', String(30), unique=True, nullable=False), Column('de_titulo', Boolean, nullable=False), Column('descripcion', String(150), unique=True, nullable=False), Column('cuenta_padre', Integer, ForeignKey('cuentas.id'), nullable=True) ) mapper(Cuenta, cuentas_tabla, properties={'padre':relation(Cuenta, backref='hijas')}) engine = create_engine('sqlite:///database.txt') Session = sessionmaker(bind=engine, autoflush=True, transactional=False) _metadata.create_all(bind=engine) session = Session() session.begin() activo = Cuenta(codigo='1', de_titulo=True, descripcion='Activo', padre=None) fachadaPersistencia.save(activo) caja = Cuenta(codigo='1.1', de_titulo = False, descripcion='Caja', padre=activo) fachadaPersistencia.save(caja) banco = Cuenta(codigo='1.2', de_titulo = False, descripcion='Banco', padre=activo) fachadaPersistencia.save(banco) pasivo = Cuenta(codigo='2', de_titulo=True, descripcion='Pasivo', padre=None) session.save(pasivo) session.commit() /code And i have the next exception: code Traceback (most recent call last): File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 30, in ? padre=None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 1126, in init oldinit(instance, *args, **kwargs) File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 9, in __init__ self.padre = padre File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 36, in __set__ self.impl.set(instance._state, value, None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 532, in set new_values = list(new_collection.adapt_like_to_iterable(value)) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/collections.py, line 509, in adapt_like_to_iterable raise TypeError( TypeError: Incompatible collection type: NoneType is not list-like /code If I quit the backref, i'm still having that error. If anybody can help me, i will appreciate that. Thanks, Marcos Alcazar Mendoza, Argentina --~--~-~--~~~---~--~~ 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: Problem: TypeError: Incompatible collection type
eh, sorry, RTFM, uselist without _underscore On Monday 14 July 2008 16:42:05 Marcos wrote: a reference - as it is in your case (padre means parent, right?) Yes, padre means parent give relation( ... use_list=False). Mmmm... no: code Traceback (most recent call last): File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab/ src/jContab/test.py, line 20, in ? mapper(Cuenta, cuentas_tabla, properties={'padre':relation(Cuenta,use_list=False)}) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/__init__.py, line 269, in relation return PropertyLoader(argument, secondary=secondary, **kwargs) TypeError: __init__() got an unexpected keyword argument 'use_list' /code I did it right? or I made a mistake? Thanks for your reply, Marcos On 14 jul, 10:11, [EMAIL PROTECTED] wrote: AFAIRemember, by default, relation assumes it is a collection, and not a reference - as it is in your case (padre means parent, right?) give relation( ... use_list=False). On Monday 14 July 2008 15:21:48 Marcos wrote: Hello! First, sorry about my english! I'm having this little problem, and i can't see where is my error. I have the follow code: code from sqlalchemy import * from sqlalchemy.orm import * class Cuenta(object): def __init__(self, codigo, de_titulo, descripcion, padre): self.codigo = codigo self.de_titulo = de_titulo self.descripcion = descripcion self.padre = padre _metadata = MetaData() cuentas_tabla = Table('cuentas', _metadata, Column('id', Integer, primary_key=True), Column('codigo', String(30), unique=True, nullable=False), Column('de_titulo', Boolean, nullable=False), Column('descripcion', String(150), unique=True, nullable=False), Column('cuenta_padre', Integer, ForeignKey('cuentas.id'), nullable=True) ) mapper(Cuenta, cuentas_tabla, properties={'padre':relation(Cuenta, backref='hijas')}) engine = create_engine('sqlite:///database.txt') Session = sessionmaker(bind=engine, autoflush=True, transactional=False) _metadata.create_all(bind=engine) session = Session() session.begin() activo = Cuenta(codigo='1', de_titulo=True, descripcion='Activo', padre=None) fachadaPersistencia.save(activo) caja = Cuenta(codigo='1.1', de_titulo = False, descripcion='Caja', padre=activo) fachadaPersistencia.save(caja) banco = Cuenta(codigo='1.2', de_titulo = False, descripcion='Banco', padre=activo) fachadaPersistencia.save(banco) pasivo = Cuenta(codigo='2', de_titulo=True, descripcion='Pasivo', padre=None) session.save(pasivo) session.commit() /code And i have the next exception: code Traceback (most recent call last): File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab / src/jContab/test.py, line 30, in ? padre=None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 1126, in init oldinit(instance, *args, **kwargs) File /home/marcos/easyeclipse-python-1.2.2.2/workspace/mine/jContab / src/jContab/test.py, line 9, in __init__ self.padre = padre File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 36, in __set__ self.impl.set(instance._state, value, None) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/attributes.py, line 532, in set new_values = list(new_collection.adapt_like_to_iterable(value)) File /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.2-py2.4.egg/ sqlalchemy/orm/collections.py, line 509, in adapt_like_to_iterable raise TypeError( TypeError: Incompatible collection type: NoneType is not list-like /code If I quit the backref, i'm still having that error. If anybody can help me, i will appreciate that. Thanks, Marcos Alcazar Mendoza, Argentina --~--~-~--~~~---~--~~ 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: M2M relationship
Hello Michael, what I see immediately is that you're declaring mutliple declarative_bases and multiple MetaData objects. All of the Table objects which relate to one another need to share the same underlying MetaData object, and the declarative_base() function also uses a MetaData object which it creates for you, unless one is passed. So you need a global module everyone works from which starts with something like: meta = MetaData() Base = declarative_base(metadata=meta) then every Table uses the above meta as its metadata argument, every declared mapped class inherits from Base. Thank you kindly for this concept, I really appreciate your advice thus far. I'm still struggling with this same challenge though, I've got a horrible dose of n00bitus I'm afraid. Above you talk about a global module in the application which creates the Base and metadata, but I don't understand how these can then be accessed by other classes around the application? Do you have any good sample code or a link to a decent tutorial? Seems all I can find are examples which are based on the idea that all the classes are defined in the same module, which isn't practical. I really appreciate the help Michael, thanks. Heston --~--~-~--~~~---~--~~ 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: Problem: TypeError: Incompatible collection type
uselist without _underscore Thanks, that works. RTFM And thanks for the insult, I will try to read more before to ask. Marcos --~--~-~--~~~---~--~~ 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: M2M relationship
On Jul 14, 2008, at 11:02 AM, Heston James - Cold Beans wrote: Hello Michael, what I see immediately is that you're declaring mutliple declarative_bases and multiple MetaData objects. All of the Table objects which relate to one another need to share the same underlying MetaData object, and the declarative_base() function also uses a MetaData object which it creates for you, unless one is passed. So you need a global module everyone works from which starts with something like: meta = MetaData() Base = declarative_base(metadata=meta) then every Table uses the above meta as its metadata argument, every declared mapped class inherits from Base. Thank you kindly for this concept, I really appreciate your advice thus far. I'm still struggling with this same challenge though, I've got a horrible dose of n00bitus I'm afraid. Above you talk about a global module in the application which creates the Base and metadata, but I don't understand how these can then be accessed by other classes around the application? create a file called something like globals.py, and in all other modules that use SQLAlchemy, say import globals. A primer on modules, packages and such is at http://www.python.org/doc/tut/node8.html . --~--~-~--~~~---~--~~ 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: M2M relationship
Heston wrote: [SNIP] Above you talk about a global module in the application which creates the Base and metadata, but I don't understand how these can then be accessed by other classes around the application? Do you have any good sample code or a link to a decent tutorial? Seems all I can find are examples which are based on the idea that all the classes are defined in the same module, which isn't practical. Hi Heston, This is really a plain python question rather than an SQLAlchemy question. You might find this section of the python tutorial useful: http://docs.python.org/dev/tutorial/modules.html But basically, if you put the following code in a module called 'base.py': #- from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import MetaData meta = MetaData() Base = declarative_base(metadata=meta) #- Then in your other modules you can write: #- import base class Post(base.Base): __tablename__ = 'post' # etc. #- Hope that helps, Simon --~--~-~--~~~---~--~~ 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: Problem: TypeError: Incompatible collection type
On Jul 14, 2008, at 10:46 AM, [EMAIL PROTECTED] wrote: eh, sorry, RTFM, uselist without _underscore if that was not addressed to yourself, try to refrain from using that kind of tone...even if it were meant humorously, things like that don't travel well via email. --~--~-~--~~~---~--~~ 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: Little Bug - orm.object_mapper.get_property
not seeing it: # pydoc sqlalchemy.orm.mapperlib.Mapper.get_property Help on method get_property in sqlalchemy.orm.mapperlib.Mapper: sqlalchemy.orm.mapperlib.Mapper.get_property = get_property(self, key, resolve_synonyms=False, raiseerr=True) unbound sqlalchemy.orm.mapper.Mapper method return a MapperProperty associated with the given key. On Jul 14, 2008, at 3:45 AM, Kless wrote: I refer to the docstring and this is my version: SQLAlchemy-0.5.0beta1- py2.5.egg On Jul 14, 1:59 am, Michael Bayer [EMAIL PROTECTED] wrote: On Jul 13, 2008, at 1:38 PM, Kless wrote: *orm.object_mapper* has an argument called 'raiseerror', and it works ok. *orm.object_mapper.get_property* also has an argument called 'raiseerror' (that says on documentation), but it fails: *unexpected keyword argument 'raiseerror'*. It's using as argument: 'raiseerr'. I dont like those raiseerror flags very much and in reality I'd like to take them out. Although I am not seeing the get_property() documentation you're referring to, in both 0.4 and 0.5 the docstring does not describe the arguments for that method. --~--~-~--~~~---~--~~ 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] SQLAlchemy 0.5beta2 released
0.5 beta2 released 0.5 is pretty much done for the 0.5.0 release, we're not anticipating any more backwards-incompatible changes, or only very small ones. beta2 is to get the current functionality out there (even though most 0.5 beta users might be using trunk anyway). Also see the migration guide at http://www.sqlalchemy.org/trac/wiki/05Migration where I've added a full explaination of the change regarding the .c. attribute on classes. Download SQLAlchemy 0.5beta2 at: http://www.sqlalchemy.org/download.html 0.5beta2 - 0.5beta2 includes all bugfixes listed under release 0.4.7. - orm - In addition to expired attributes, deferred attributes also load if their data is present in the result set. [ticket:870] - session.refresh() raises an informative error message if the list of attributes does not include any column-based attributes. - query() raises an informative error message if no columns or mappers are specified. - lazy loaders now trigger autoflush before proceeding. This allows expire() of a collection or scalar relation to function properly in the context of autoflush. - column_property() attributes which represent SQL expressions or columns that are not present in the mapped tables (such as those from views) are automatically expired after an INSERT or UPDATE, assuming they have not been locally modified, so that they are refreshed with the most recent data upon access. [ticket:887] - Fixed explicit, self-referential joins between two joined-table inheritance mappers when using query.join(cls, aliased=True). [ticket:1082] - Fixed query.join() when used in conjunction with a columns-only clause and an SQL-expression ON clause in the join. - The allow_column_override flag from mapper() has been removed. This flag is virtually always misunderstood. Its specific functionality is available via the include_properties/exclude_properties mapper arguments. - Repaired `__str__()` method on Query. [ticket:1066] - Session.bind gets used as a default even when table/mapper specific binds are defined. - schema - Added prefixes option to `Table` that accepts a list of strings to insert after CREATE in the CREATE TABLE statement. [ticket:1075] - Unicode, UnicodeText types now set assert_unicode and convert_unicode by default, but accept overriding **kwargs for these values. - sql - Added new match() operator that performs a full-text search. Supported on PostgreSQL, SQLite, MySQL, MS-SQL, and Oracle backends. - sqlite - Modified SQLite's representation of microseconds to match the output of str(somedatetime), i.e. in that the microseconds are represented as fractional seconds in string format. This makes SQLA's SQLite date type compatible with datetimes that were saved directly using Pysqlite (which just calls str()). Note that this is incompatible with the existing microseconds values in a SQLA 0.4 generated SQLite database file. To get the old behavior globally: from sqlalchemy.databases.sqlite import DateTimeMixin DateTimeMixin.__legacy_microseconds__ = True To get the behavior on individual DateTime types: t = sqlite.SLDateTime() t.__legacy_microseconds__ = True Then use t as the type on the Column. [ticket:1090] - SQLite Date, DateTime, and Time types only accept Python datetime objects now, not strings. If you'd like to format dates as strings yourself with SQLite, use a String type. If you'd like them to return datetime objects anyway despite their accepting strings as input, make a TypeDecorator around String - SQLA doesn't encourage this pattern. - extensions - Declarative supports a __table_args__ class variable, which is either a dictionary, or tuple of the form (arg1, arg2, ..., {kwarg1:value, ...}) which contains positional + kw arguments to be passed to the Table constructor. [ticket:1096] --~--~-~--~~~---~--~~ 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: Little Bug - orm.object_mapper.get_property [Wrong]
Sorry! I suppose that I was confused. On Jul 14, 8:34 pm, Michael Bayer [EMAIL PROTECTED] wrote: not seeing it: # pydoc sqlalchemy.orm.mapperlib.Mapper.get_property Help on method get_property in sqlalchemy.orm.mapperlib.Mapper: sqlalchemy.orm.mapperlib.Mapper.get_property = get_property(self, key, resolve_synonyms=False, raiseerr=True) unbound sqlalchemy.orm.mapper.Mapper method return a MapperProperty associated with the given key. On Jul 14, 2008, at 3:45 AM, Kless wrote: I refer to the docstring and this is my version: SQLAlchemy-0.5.0beta1- py2.5.egg On Jul 14, 1:59 am, Michael Bayer [EMAIL PROTECTED] wrote: On Jul 13, 2008, at 1:38 PM, Kless wrote: *orm.object_mapper* has an argument called 'raiseerror', and it works ok. *orm.object_mapper.get_property* also has an argument called 'raiseerror' (that says on documentation), but it fails: *unexpected keyword argument 'raiseerror'*. It's using as argument: 'raiseerr'. I dont like those raiseerror flags very much and in reality I'd like to take them out. Although I am not seeing the get_property() documentation you're referring to, in both 0.4 and 0.5 the docstring does not describe the arguments for that method. --~--~-~--~~~---~--~~ 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] unexpected behavior with relation and filter_by
With the following schema: Table(u'account', meta, Column(u'id', Integer(), primary_key=True, nullable=False), Column(u'name', String(length=5, convert_unicode=False, assert_unicode=None), nullable=False)) Table(u'license', meta, Column(u'id', Integer(), primary_key=True, nullable=False), Column(u'accountid', Integer(), ForeignKey(u'account.id'))) and the following mapper configuration: mapper(Account, meta.tables['account'], properties = { 'licenses': sa_orm.relation( License, lazy=True, backref='account', uselist=True, # probably redundant ), }, **mapper_kwargs ) mapper(License, meta.tables['license'], **mapper_kwargs) I've encountered some weird stuff. I'm probably doing it wrong, but I don't understand *why*. The following code: s = Session() # returns all accounts, the .licenses param # not taken into consideration accts = s.query(Account).filter(Account.licenses==[]) print accts print accts = s.query(Account).filter(Account.licenses.any()) print accts print # returns the correct list of accounts. accts = s.query(Account).filter(Account.licenses==None) print accts print print accts[0].licenses # prints [] not None. produces the following output: SELECT account.id AS account_id, account.name AS account_name FROM account ORDER BY account.id SELECT account.id AS account_id, account.name AS account_name FROM account WHERE EXISTS (SELECT 1 FROM license WHERE account.id = license.accountid) ORDER BY account.id SELECT account.id AS account_id, account.name AS account_name FROM account WHERE NOT (EXISTS (SELECT 1 FROM license WHERE account.id = license.accountid)) ORDER BY account.id [] The last two queries produce the desired results but the first doesn't, but it doesn't generate any errors, either. The first query is what I originally wrote as it is what I simply transcribed from what I was thinking: Query for Account objects for which the licenses attribute is an empty list. accts = s.query(Account).filter(Account.licenses==[]) I'm using 0.4.6 and PostgreSQL 8.3.1 --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---