Problem: TypeError: Incompatible collection type

2,024 views
Skip to first unread message

Marcos

unread,
Jul 14, 2008, 8:21:48 AM7/14/08
to sqlalchemy
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

a...@svilendobrev.com

unread,
Jul 14, 2008, 9:11:09 AM7/14/08
to sqlal...@googlegroups.com
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).

Marcos

unread,
Jul 14, 2008, 9:42:05 AM7/14/08
to sqlalchemy
> 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

a...@svilendobrev.com

unread,
Jul 14, 2008, 10:46:53 AM7/14/08
to sqlal...@googlegroups.com
eh, sorry, RTFM, uselist without _underscore

Marcos

unread,
Jul 14, 2008, 11:05:18 AM7/14/08
to sqlalchemy
> uselist without _underscore
Thanks, that works.

> RTFM
And thanks for the insult, I will try to read more before to ask.

Marcos

Michael Bayer

unread,
Jul 14, 2008, 11:14:26 AM7/14/08
to sqlal...@googlegroups.com

On Jul 14, 2008, at 10:46 AM, a...@svilendobrev.com 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.

Reply all
Reply to author
Forward
0 new messages