1. Michael Bayer
  2. SQLSoup
  3. Issues
Issue #2 new

Support for non-scoped Sessions is broken

Anonymous created an issue

The docstring for SQLSoup says:

        :param session: a :class:`.ScopedSession` or :class:`.Session` with
          which to associate ORM operations for this :class:`.SQLSoup` instance.
          If ``None``, a :class:`.ScopedSession` that's local to this 
          module is used.

But a plain Session doesn't work since you will get:

>>> import sqlsoup, sqlalchemy.orm as orm, sqlalchemy as sa
>>> eng=sa.create_engine('sqlite:///')
>>> ses=orm.Session(eng)
>>> soup=sqlsoup.SQLSoup(eng,session=ses)
>>> ses.execute('create table y (a int primary key);')
>>> soup.y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yang/.virtualenvs/wab/local/lib/python2.7/site-packages/sqlsoup.py", line 455, in __getattr__
    return self.entity(attr)
  File "/home/yang/.virtualenvs/wab/local/lib/python2.7/site-packages/sqlsoup.py", line 452, in entity
    return self.map_to(attr, tablename=attr, schema=schema)
  File "/home/yang/.virtualenvs/wab/local/lib/python2.7/site-packages/sqlsoup.py", line 363, in map_to
    mapper_args
  File "/home/yang/.virtualenvs/wab/local/lib/python2.7/site-packages/sqlsoup.py", line 175, in _class_for_table
    klass._query = session.query_property()
AttributeError: 'Session' object has no attribute 'query_property'

It seems important to be able to support non-scoped sessions.

Comments (1)

  1. Michael Bayer repo owner

    here's part of a patch but unfortunately this needs more work, as the session here maintains a transaction which isn't shared with the engine passed to the sqlsoup instance. i'll gladly accept pullrequests building off this patch.

  2. Log in to comment