Commit 079cfe58 authored by Kirill Smelkov's avatar Kirill Smelkov

ERP5Type.Base: .serialize() is possible without writing object to DB

There is no need to write object to DB just to make sure it stays the
same - since ZODB 3.10 there is explicit way to constraint commit to
succeed only if an object does not change[1] :

    Connection.readCurrent(obj)

All FileStorage [2], ZEO [3] and NEO [4,5] should support this.

[1] https://github.com/zopefoundation/ZODB/commit/5a9afb14
[2] https://github.com/zopefoundation/ZODB/commit/99cbe353
[3] https://github.com/zopefoundation/ZODB/commit/a3de2ce8
[4] http://git.erp5.org/gitweb/neoppod.git/commitdiff/af5253bd
[5] http://git.erp5.org/gitweb/neoppod.git/commitdiff/40652c1c

/cc @vpelletier, @jm
parent 9cc0460e
...@@ -3262,7 +3262,14 @@ class Base( CopyContainer, ...@@ -3262,7 +3262,14 @@ class Base( CopyContainer,
def serialize(self): def serialize(self):
"""Make the transaction accessing to this object atomic """Make the transaction accessing to this object atomic
""" """
self._p_changed = 1 # we don't have anything to do if this is a newly created object, never
# committed and thus not yet registered to Connection - if it is reachable
# from database root, the object will be stored to database on commit.
if self._p_jar is None:
return
# ask ZODB to make sure the object stays unchanged at commit
self._p_jar.readCurrent(self)
# Helpers # Helpers
def getQuantityPrecisionFromResource(self, resource, d=2): def getQuantityPrecisionFromResource(self, resource, d=2):
......
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