Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SQLAlchemy - Mapping ResultProxy to mapped classes without a session
- session.query(SomeClass)
- engine = create_engine('sqlite:///:memory:')
- meta = MetaData()
- meta.bind = engine
- table = Table('table, meta,
- Column('id', Integer, primary_key=True),
- Column('field1', String(16), nullable=False),
- Column('field2', String(60)),
- Column('field3', String(20), nullable=False)
- )
- class Table(object)
- pass
- meta.create_all(checkfirst=True)
- for i in range(10):
- user.insert({'field1': 'field1'+i,'field2': 'field2'+i*2,'field3': 'field3'+i*4})
- mapper(Table, table)
- query = Query((Table,))
- query.instances(engine.text("SELECT * FROM table").execute())
- Traceback (most recent call last):
- File "sqlalchemy/orm/mapper.py", line 2507, in _instance_processor
- session_identity_map = context.session.identity_map
- AttributeError: 'NoneType' object has no attribute 'identity_map'
Add Comment
Please, Sign In to add comment