Hello,
I've just found out that SA fails to work correctly on object that feature a
metaclass. It seems to have little to do with the metaclass behaviour, it
actually happens even using a bare type as metaclass - which is the standard
Python behaviour, and just creates the object class.
What I spotted is that the class __init__ method is not called whenever
getting an object via a query.
I've not had enough time to investigate it, I'll do in the next days. In the
meantime I'm attaching the demo of the issue.
(I think there're a couple of typos in the file 'cause I wrote it very
quickly, but it's just about printed strings. the program runs fine).
--
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---
from sqlalchemy import *
connect_params = "postgres://user:[EMAIL PROTECTED]:5432/kiwi"
engine = create_engine(connect_params, echo=False, convert_unicode=True)
metadata = BoundMetaData(engine)
prove = Table("prove", metadata,
Column("id", Integer, Sequence("prove_id_seq"), primary_key=True, nullable=False),
Column("testo", String(30)),
Column("numero_lungo", Integer),
)
metadata.create_all()
class MappedObject(object):
__metaclass__ = type
def __init__(self, testattr="default"):
print "inizialization done!"
self._testattr = testattr
super(MappedObject, self).__init__()
m = mapper(MappedObject, prove)
a = MappedObject("value")
a.testo = "onetwothree"
print "testattr:",a._testattr
print "isobject:",isinstance(a, object)
session = create_session()
session.save(a)
session.flush()
session.clear()
del a
query = session.query(MappedObject)
b = query.get_by(testo="onetwothree")
print b
print b._testattr