Zope 2.12 PythonScript manage_change_history_page functionalities broken for old objects
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 2 |
Invalid
|
Low
|
Unassigned |
Bug Description
How to reproduce:
- Create an instance with an old Zope version (in my case: 2.8.8)
- Create a PythonScript object, maybe edit a few times (just to have more than one revisions, to show the problem is not an edge case of a new object)
- Upgrade to newer Zope (in my case: 2.12)
- Go to the same PythonScript, maybe edit again a few times (same goal as above)
- Go to History page
- Try to diff script with an old revision of itself, or to display old revisions
What happens:
When one of the loaded revision was created before the upgrade, it fails with an AssertionError in ZOPE/Connection
Indeed:
(Pdb) obj._p_
<class OFS.History.
(Pdb) self.__class__
<class 'ZODB.Connectio
This happens, as far as I understand, because of this:
> Zope2-2.
((Pdb)) getattr(self, 'Python_magic', None)
'm\xf2\r\n'
((Pdb)) Python_magic
'\xd1\xf2\r\n'
Which leads to...
229 if body:
230 self._body = body + '\n'
And assigning to self._body in turn causes object to be registered to ZODB.Connection, in turn causing the assertion error.
Changed in zope2: | |
importance: | Undecided → Low |
status: | New → Confirmed |
Attached patch fixes the problem for me.
I applied the same order here as what happens when calling ZODB.Connection .load: first __setstate__, then put _p_serial, and finally prevent any change by setting a different jar.
Notes (unrelated to this fix, but related to modified code): __class_ _.__basicnew_ _()
- This function breaks if object class changed between observed and current revision
Reason: rev=self.
Possible solution: ZODB should probably offer a way to load an old instance into a usable object, rather than exposing a bare state.
- HystoryJar is not strictly required to raise in commit actually. It's anyway probably better to keep it here, in case ZODB stops checking jar (...not that I think it will really happen).