Commit 245f197c authored by Jason Madden's avatar Jason Madden

Deleting the jar of a ghosted Python persistent object shouldn't try to...

Deleting the jar of a ghosted Python persistent object shouldn't try to activate it. This was an error encountered testing ZEO:

```python
File "//Projects/GithubSources/ZEO/src/ZEO/tests/testZEO.py", line 1566, in ZEO.tests.testZEO.gracefully_handle_abort_while_storing_many_blobs
Failed example:
    c.tpc_abort(t)
Exception raised:
    Traceback (most recent call last):
      File "//bin/pypy/lib-python/2.7/doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest ZEO.tests.testZEO.gracefully_handle_abort_while_storing_many_blobs[12]>", line 1, in <module>
        c.tpc_abort(t)
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/ZODB-4.2.0.dev0-py2.7.egg/ZODB/Connection.py", line 754, in tpc_abort
        self._invalidate_creating()
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/ZODB-4.2.0.dev0-py2.7.egg/ZODB/Connection.py", line 775, in _invalidate_creating
        del o._p_jar
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/persistent-4.0.10.dev0-py2.7.egg/persistent/persistence.py", line 287, in __delattr__
        object.__delattr__(self, name)
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/persistent-4.0.10.dev0-py2.7.egg/persistent/persistence.py", line 92, in _del_jar
        self.__setattr__('_Persistent__jar', None)
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/persistent-4.0.10.dev0-py2.7.egg/persistent/persistence.py", line 249, in __getattribute__
        oga(self, '_p_activate')()
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/persistent-4.0.10.dev0-py2.7.egg/persistent/persistence.py", line 358, in _p_activate
        jar.setstate(self)
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/ZODB-4.2.0.dev0-py2.7.egg/ZODB/Connection.py", line 869, in setstate
        self._setstate(obj)
      File "//Projects/VirtualEnvs/ZODBpypy/site-packages/ZODB-4.2.0.dev0-py2.7.egg/ZODB/Connection.py", line 910, in _setstate
        p, serial = self._storage.load(obj._p_oid, '')
      File "//Projects/GithubSources/ZEO/src/ZEO/ClientStorage.py", line 842, in load
        data, tid = self._server.loadEx(oid)
      File "//Projects/GithubSources/ZEO/src/ZEO/ServerStub.py", line 176, in loadEx
        return self.rpc.call("loadEx", oid)
      File "//Projects/GithubSources/ZEO/src/ZEO/zrpc/connection.py", line 781, in call
        raise inst # error raised by server
    POSKeyError: 0x02'')
```
parent 39c237c6
......@@ -85,11 +85,10 @@ class Persistent(object):
def _del_jar(self):
jar = self.__jar
oid = self.__oid
if jar is not None:
if self._p_is_in_cache():
raise ValueError("can't delete _p_jar of cached object")
self.__setattr__('_Persistent__jar', None)
_OSA(self, '_Persistent__jar', None)
_OSA(self, '_Persistent__flags', None)
_p_jar = property(_get_jar, _set_jar, _del_jar)
......
......@@ -112,6 +112,29 @@ class _Persistent_Base(object):
del inst._p_jar
self.assertEqual(inst._p_jar, None)
def test_del_jar_of_inactive_object_that_has_no_state(self):
# If an object is ghosted, and we try to delete its
# jar, we shouldn't activate the object.
# Simulate a POSKeyError on _p_activate; this can happen aborting
# a transaction using ZEO
broken_jar = self._makeBrokenJar()
inst = self._makeOne()
inst._p_oid = 42
inst._p_jar = broken_jar
# make it inactive
if hasattr(inst, '_Persistent__flags'):
# Python version
inst._Persistent__flags = None
else:
inst._p_deactivate()
self.assertEqual(inst._p_status, "ghost")
# delete the jar; if we activated the object, the broken
# jar would raise NotImplementedError
del inst._p_jar
def test_assign_p_jar_w_new_jar(self):
inst, jar, OID = self._makeOneWithJar()
new_jar = self._makeJar()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment