On Jan 30, 3:54 pm, Michael Bayer <[email protected]> wrote:
> On Jan 30, 2013, at 5:43 AM, George Sakkis wrote:
>
> > Hello,
>
> > I am in the process of migrating to PyPy and have a handful of unit test
> > failing due to the different garbage collector and SQLAlchemy's usage of
> > weak references in the Session identity map. Most failures are probably
> > safe to ignore and all of them are fixed after manually calling
> > gc.collect() somewhere in the test.
>
> this is true but FTR we do have a pypy suite up on jenkins.sqlalchemy.org, we
> don't run it often because it takes hours, but we did go through lots of
> effort to ensure that all the tests pass, and those that just really need
> cPython's GC are skipped. Unless you're referring to your own tests.....
Yes I meant my tests, not the SQLAlchemy test suite; sorry for the
confusion.
> > One specific failure though looks more worrying: a Session.rollback() call
> > in the test's tearDown() method raises "InvalidRequestError: Can't attach
> > instance `X`; another instance with key (<class `X`>, (8L, 1L)) is already
> > present in this session." Before digging deeper, any idea on why it is
> > triggered here and not in any other test?
>
> it would be impossible to say without specific details and examples.
> Generally there is probably some logic that relies upon an X(8, 1) being
> garbage collected from the Session (note the identity map is weak
> referencing) so that an add() later on can succeed. An add() inside of a
> tearDown() is kind of strange, though, the stack trace would tell you how
> it's getting there.
Here's the relevant stacktrace:
Traceback (most recent call last):
File "/home/gsakkis/pdo/src/hoist/test/__init__.py", line 55, in
tearDown
Session.rollback()
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/scoping.py", line 114, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/session.py", line 673, in rollback
self.transaction.rollback()
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/session.py", line 387, in rollback
transaction._rollback_impl()
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/session.py", line 418, in _rollback_impl
self._restore_snapshot()
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/session.py", line 275, in _restore_snapshot
self.session._update_impl(s)
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/session.py", line 1621, in _update_impl
self._attach(state)
File "/home/gsakkis/pdo/.virtualenv_pypy/site-packages/sqlalchemy/
orm/session.py", line 1649, in _attach
% (mapperutil.state_str(state), state.key))
InvalidRequestError: Can't attach instance <MyModel at 0x87fcc60>;
another instance with key (<class 'my_package.MyModel'>, (8L, 1L)) is
already present in this session.
"MyModel" is a declarative_base() subclass. By the way the exception
is not raised consistently, sometimes the test passes.
> > Is there another/better way to prevent it other than calling gc.collect()
> > before Session.rollback() (and perhaps other Session operations)?
>
> I'd make sure the tests use a brand new Session for every test that's clean.
That should be the case; setUp() calls Session.begin() and tearDown()
calls:
try:
Session.rollback()
finally:
Session.remove()
The Session is in autocommit mode.
> > More generally, are there any other known issues and caveats of running
> > SQLAlchemy on PyPY?
>
> Our own test suite has a lot of performance issues with Pypy, not sure if due
> to memory or JIT crunching or what, I reported it to their bug tracker at the
> request of their developers.
Do you happen to run coverage along with tests (--with-xcoverage)? If
yes that must be the reason; at least in our case removing the
coverage reduced the overhead from 10x the time of CPython down to
~15%.
Thanks,
George
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.