Hello All,

I was curious if anyone else has run into this error:

<error message>

Traceback (most recent call last):
  File "util/sa/tests/test_sa_dao.py", line 96, in setUp
    self.session.add(tc1)
  File
"/home/adorsk/projects/gr/jenv2.7/Lib/site-packages/sqlalchemy/orm/session.py",
line 1251, in add
    self._save_or_update_state(state)
  File
"/home/adorsk/projects/gr/jenv2.7/Lib/site-packages/sqlalchemy/orm/session.py",
line 1262, in _save_or_update_state
    mapper = _state_mapper(state)
AttributeError: 'InstanceState' object has no attribute 'manager.mapper'

</error message>

The context in which this error message is generated is pasted below.

I'm using Jython2.7 on a Postgres, via xzJDBC and the Postgresql JDBC
driver.

If you did encounter this error, did you find a workaround?

-Alex

P.S. SqlAlchemy is absolutely brilliant!  Beautiful docs and code,
definitely my new favorite python tool.



<code>

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()

</code>

-- 
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.

Reply via email to