unfortunately issues like these are often resulting from Jython bugs. For
example, SQLAlchemy was entirely unusable with the previous version of Jython
due to a bug in their __import__ mechanism. That the test works fine using
regular cPYthon with psycopg2 further points to some incompatibility/quirk in
Jython as a potential culprit.
As a test, since I don't have Jython installed, what does this produce for you ?
class Foo(object):
pass
class Bar(object):
pass
f = Foo()
f.bar = Bar()
f.bar.bat = 5
from operator import attrgetter
print attrgetter("bar.bat")(f)
if you get that same error, then this is the Jython bug - attrgetter() as of
2.6 handles dotted paths. SQLAlchemy does have a "workaround" version for
Python less than 2.6 which we can also enable for Jython, for the interim, but
also this should be reported to Jython as a bug.
On Jun 6, 2012, at 10:37 AM, Alexander Dorsk wrote:
> import unittest
>
> from sqlalchemy import Table, Column, ForeignKey, ForeignKeyConstraint,
> Integer, String, Float, MetaData, create_engine
> from sqlalchemy.orm import relationship, mapper
> from geoalchemy import *
> from geoalchemy.postgis import PGComparator
> from sqlalchemy.orm import sessionmaker
>
> class My_Test(unittest.TestCase):
>
> def testFoo(self):
> print "foo"
>
> def setUp(self):
> self.engine =
> create_engine('postgresql+zxjdbc://MY_DB:MY_USER@localhost/MY_PASS)
> self.Session = sessionmaker()
> connection = self.engine.connect()
>
> # begin a non-ORM transaction
> self.trans = connection.begin()
>
> # bind an individual Session to the connection
> self.session = self.Session(bind=connection)
>
> schema = {}
> self.schema = schema
> schema['classes'] = {}
>
> class TestClass1(object):
> id = None
> children = []
> schema['classes']['TestClass1'] = TestClass1
>
> class TestClass2(object):
> id = None
> name = ""
> schema['classes']['TestClass2'] = TestClass2
>
> schema['primary_class'] = TestClass1
>
> metadata = MetaData()
>
> test1_table = Table('test1', metadata,
> Column('id', Integer, primary_key=True)
> )
>
> test2_table = Table('test2', metadata,
> Column('id', Integer, primary_key=True),
> Column('name', String)
> )
>
> test1_test2_table = Table('test1_test2', metadata,
> Column('test1_id', Integer, primary_key=True),
> Column('test2_id', Integer, primary_key=True),
> ForeignKeyConstraint(['test1_id'], [test1_table.c.id]),
> ForeignKeyConstraint(['test2_id'], [test2_table.c.id])
> )
>
> mapper(
> TestClass1,
> test1_table,
> properties = {
> 'children': relationship(TestClass2,
> secondary=test1_test2_table)
> }
> )
>
> mapper(
> TestClass2,
> test2_table,
> properties = {
> }
> )
>
> metadata.create_all(self.session.bind)
>
> tc1s = []
> tc2s = []
> for i in range(5):
> tc1 = TestClass1()
> tc1s.append(tc1)
> self.session.add(tc1)
>
> tc2 = TestClass2()
> tc2.name = "tc2_%s" % i
> tc2s.append(tc2)
> self.session.add(tc2)
>
> self.session.commit()
>
> for i in range(len(tc1s)):
> tc1 = tc1s[i]
> child_tc2s = [tc2s[i], tc2s[ (i + 1) % len(tc1s)]]
> for c in child_tc2s:
> tc2 = self.session.query(TestClass2).filter(TestClass2.id ==
> c.id).one()
> tc1.children.append(tc2)
>
> self.session.commit()
>
> if __name__ == '__main__':
> unittest.main()
--
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.